Melvita Menezes
Melvita Menezes

Reputation: 1

how to use regular expression in javascript

var pattern=/[A-za-z0-9]/;
if((fs.value||ls.value||ad1.value||ad2.value||pc.value||city.value||email.value)!=pattern)
{alert("fields not entered");
return false;}
else
return true;

Even after entering all the fields in the form, I get alert message "field not entered. Here fs,ls,ad1,ad2,email,pc and city are form field values

Upvotes: 0

Views: 58

Answers (1)

Shaun Sweet
Shaun Sweet

Reputation: 689

You need to take the values from those fields and run them thru the regex matching tool while passing the regex to that method.

var pattern=/[A-za-z0-9]/;
"string to check against regex pattern".match(pattern);

See more here

Upvotes: 1

Related Questions