![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
Registered User
|
function emailVal()
{ var strEmail = document.frmCheese.txtEmail.value; //value of entered email addres var strExp = (/\w+[\.-]?\w+@\w+\.\w{3}(\.\w{2})?/) ; //string to test the email address... var strReg = new RegExp(strExp,"i"); if (strReg.test(strEmail)) //email value checking using { checkPw(); } else { window.alert(strReg + "\n" + strEmail ); window.alert("Your emailaddress is invalid. \nPlease enter a correct email address"); document.frmCheese.txtEmail.value = ""; document.frmCheese.txtEmail.focus(); } } For a tafe project I am trying to validate the date, the above is my code. Where is the mistake... Wizz |
|
|
|
|
|
#2 (permalink) |
|
Registered User
|
Sorry guys after hours of trying to fix this relatively simple coding, my eyes and brains weren't working very well...
![]() Yes I also had problems with date validation, but most of that is sorted, albeit not in a nice fashion... used if-statements instead of a nice for-loop... back to this question I ofcourse meant a email validation not date validation. ![]() I tried RegExp in different forms... but I could not get it to work, so I used .indexOf("@") so if there is an @ anywhere in the string, the email is valid. ![]() I rather use the RegExp - looks much spiffi-er! The following code should work, but it doesn't: ---------- var strEmail = document.frmCheese.txtEmail.value; //I checked the value of strEmail and the value of txtEmail is in it. var strExp = ("\w+[\.-]?\w+@\w+\.\w{3}(\.\w{2})?") ; /I checked the value of strExp is there, but many "\" are missing? var strReg = new RegExp(strExp,"i"); if (strReg.test(strEmail)) //does 'test' has to be something else? ----------- if (strReg.test(strEmail)== true) if (strReg.test("strEmail")) - i tried didn't work and more variations! strRegExp I had originally but I thought maybe a word that is used already... According to my understanding this RegExp expression would allow: some letters, "." or "-", more letters, "@" more letters "." 3 letters ("." 2 letters) - but optional. If I could get this to work, I would replace 3 letters with (com | net | org | edu |...) etc, to get even better grades! Now can anybody have a glans and the code and give me a hint where the mistake is? I like to know before Wednesday if that is possible.... ![]() Wizz Last edited by wizzbone : 06-14-2008 at 02:43 AM. |
|
|
|
![]() |
| Thread Tools | |
|
|