email validation in JavaScript
Sorry guys after hours of trying to fix this relatively simple coding, my eyes and brains weren't working very well...:upset:
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. :4-thatsba
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.:4-dontkno :sigh:
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+[\.-]?\[email protected]\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
Sorry guys after hours of trying to fix this relatively simple coding, my eyes and brains weren't working very well...:upset:
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. :4-thatsba
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.:4-dontkno :sigh:
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+[\.-]?\[email protected]\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