/    Sign up×
Community /Pin to ProfileBookmark

Javascript.

Hi, if the below is the code (which works – there is more but the below is just an example) to verify a form, with just A to Z, a to z and 0 to 9 text can you please tell me what I’d need to put to make a ‘checkbox’ required please?

else if (!/^[a-z0-9]+$/i.test(form.contactNAME.value)) {
alert(“Please include your name for contact purposes.”);
form.contactNAME.select(); }

Any help you can give me will be much appreciated, thanks!

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@AdamBrillMar 13.2003 — You can check if a checkbox is checked like this:

if(form.CheckBoxName.checked==true)

So, if you want to add that into yours, it would be like this:

else if (!/^[a-z0-9]+$/i.test(form.contactNAME.value) && form.CheckBoxName.checked==true)

I hope that helps... ?
Copy linkTweet thisAlerts:
@boojumMar 13.2003 — "with just A to Z, a to z and 0 to 9"

isnt [a-z0-9]+ missing the capitol alphabet?
Copy linkTweet thisAlerts:
@AdamBrillMar 13.2003 — boojum - In RegEx, if you put an i after it, it will make it so it isn't case sensative. /^[a-z0-9]+$/ would only work with small letters and numbers, while /^[a-z0-9]+$/i works with capital letters, too. ?
Copy linkTweet thisAlerts:
@DanUKauthorMar 13.2003 — so like this?

if(form.CheckBoxName.checked==true) {

alert("Please make sure the checkbox is ticked!");

form.CheckBoxName.select(); }


this is ok?

thanks!
Copy linkTweet thisAlerts:
@JonaMar 13.2003 — You don't even have to have the ==true on there. if(form.CheckBoxName.checked) should do just fine.

P.S. Right, guys??? ?
Copy linkTweet thisAlerts:
@DanUKauthorMar 13.2003 — if(form.CheckBoxName.checked) {

alert("Please make sure the checkbox is ticked!");

form.CheckBoxName.select(); }

^^^ it's ok now ? ? ?
Copy linkTweet thisAlerts:
@JonaMar 13.2003 — Yah, I just made this:

<script>

function blah(){

if(document.forms[0].CheckName.checked){ document.forms[0].CheckName.select(); alert('ha!!'); }

}

</script>

<form><input type=checkbox name=CheckName> <input type=button onclick="blah()" value="hahahah"></form>

It works, but it's kinda controversial. You see, you want if it's NOT checked, so you could do if(!document.forms[0].CheckName.checked) instead.
Copy linkTweet thisAlerts:
@DanUKauthorMar 13.2003 — ? Thanks! ?
×

Success!

Help @DanUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...