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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern matching to validate a form - date and email?

Status
Not open for further replies.

WuCOng

Technical User
Apr 20, 2001
37
GB
How do I check that fields in a form match an email or date pattern before being sent? I can check that the fields are not null and that they contain strings of a certain length (or greater) but how do I check for a "@" and a "." character (for email validation) and a date.

I need the date to pass it to an ASP page in order to to access records from a database created between time x and y. I say this because the date format in the field may need to be of a certain format to work in a SQL statement. But I don't know what or how.

Any ASP/JavaScript people know? Thanks.
 
email:

var re = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

function valid(){

var mail1=document.myform.email1.value;

if(!re.test(mail1)){
alert("wrong email address");
return false;
}
else return true;
}


Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top