|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
validation
Hi
Below is my html document with the validation script for the form. I can't get the bit, that checks the numbers of characters entered, to work. what have i done wrong? Also, how can i check that each field in the form is checked? Thanks |
|
#2
|
|||
|
|||
|
RE: validation
Quote:
It returned when I run your script :laugh: |
|
#3
|
||||
|
||||
|
RE: validation
if what codekadiya said works for everyone please post code and be more specific with your questions.
|
|
#4
|
|||
|
|||
|
RE: RE: validation
Quote:
kendo, what do you mean by that? didn't quite understand it. |
|
#5
|
|||
|
|||
|
RE: validation
Dah, Sorry!
Forgot to post the script. Here it is: <html> <head> <title>Sign Up Form</title> <script type="text/javascript" language="JavaScript"> function validate() { var str=document.register.email.value var filter=/^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i var min = 5 var max = 10 submitOK = "True" if (filter.test(str) == false) { alert("Please input a valid email address!") submitOK = "False" } if (document.username.value.length <= min || document.username.value.length >= max) { alert("The username must contain 5 to 10 characters!") submitOK = "False" } if (submitOK == "False") { return false } } </script> </head> <body> <form name="register" action="tryjs_submitpage.htm" onsubmit="return validate()"> First name: <input type="text" name="firstname"> <br> Last name: <input type="text" name="lastname"> <br> Email address: <input type="text" name="email"> <br> Username: <input type="text" name="username"> <br> <input type="submit" value="Submit"> </form> </body> </html> //the below part of code is from the above script. if (document.username.value.length <= min || document.username.value.length >= max) { alert("The username must contain 5 to 10 characters!") submitOK = "False" } I can't get the bit (part of code above), that checks the numbers of characters entered, to work. what have i done wrong? How can i check that each field in the form is filled in? so that if the field is empty, the code will display an alert to fill in the empty field. Thanks |
|
#6
|
|||
|
|||
|
RE: validation
I modified your validate function a little. It should work now.
function validate() { var str=document.register.email.value var filter=/^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i var min = 5 var max = 10 submitOK = true if (filter.test(str) == false) { alert("Please input a valid email address!") submitOK = false } if (document.register.username.value.length <= min || document.register.username.value.length >= max) { alert("The username must contain 5 to 10 characters!") submitOK = false } if (document.register.firstname.value.length == 0) { alert("The firstname is blank!") submitOK = false } if (document.register.lastname.value.length == 0) { alert("The lastname is blank!") submitOK = false } alert(submitOK); return submitOK; } |
|
#7
|
|||
|
|||
|
RE: RE: validation
Quote:
hehehehehe. thanks for putting a smile on my face while im stuck at work! |
|
#8
|
|||
|
|||
|
RE: RE: RE: validation
Quote:
Cool... What else did I have to say when there was nothing "below"??!!!? :laugh: |
|
#9
|
|||
|
|||
|
RE: validation
Thanks for help.
It works! |
|
#10
|
|||
|
|||
|
RE: RE: validation
if(!/^w[w.-]+w@w([w.-]+w.)+[a-z]{3,5}$/i.test(email.value))
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|