Handy Regular Expressions - Regular Expression in JavaScript

If you are using JavaScript for validation then regular expressions can be easily matched using the boolean match() method on any string.

Here is a simple function in JavaScript which can be used to check a string matches a regular expression or not.

function matchString(strVal, regExVal) {
var re = new RegExp(regExVal);
if (strVal.match(re)) {
return true;
} else {
return false;

No comments:

Post a Comment

Got something to say? Don't hold it! Tell it to us.

You Might Like