Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

confirm passwords

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
0
0
CA
this must be a better way with regular expressions, any suggestions?

if (objFrm.frmPassword.value == ""){
objFrm.frmPassword.focus();
alert("Please enter a password.");
return false;
}

if (objFrm.frmPasswordConfirm.value == ""){
objFrm.frmPasswordConfirm.focus();
alert("Please confirm your password.");
return false;
}else if(!objFrm.frmPassword.value==objFrm.frmPasswordConfirm.value)
alert("passwords do not match")
}
 
sry typeO , this line should be:
}else if(objFrm.frmPassword.value!=objFrm.frmPasswordConfirm.value)

not: (!objFrm.frmPassword.value==objFrm.frmPasswordConfirm.value

 
There are other ways... but I wouldn't necessarily call them better ways. You can use regular expressions... but they will not be as easy for you (or the next person maintaining the code) to understand.

If you are unable to create your own regular expression for this simple task - then I suggest you stick with what you have... it is easy to understand for everyone.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
this isn't really a case for regular expressions. you could clean up your code a little, but i wouldn't change much, functionally...



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Why do you want to use regexp here? If all you want to do is see if a field is empty, then what you have is the best way to go.

If you want something more, then you'll need to tell us - we're not psychic ;-)

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top