Tech Support Forum banner
Status
Not open for further replies.
1 - 2 of 2 Posts

·
Registered
Joined
·
37 Posts
Discussion Starter · #1 ·
function emailVal()
{
var strEmail = document.frmCheese.txtEmail.value; //value of entered email addres
var strExp = (/\w+[\.-]?\[email protected]\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
 

·
Registered
Joined
·
37 Posts
Discussion Starter · #2 · (Edited)
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.... :eek:

Wizz
 
1 - 2 of 2 Posts
Status
Not open for further replies.
Top