Monday, March 23, 2009

Pattern matching in Javascript

var pattern1 = /^[789]{1}[\d]{2}[AaBbCcDd]{1}$/;
var pattern2 = /^[3456]{1}[1234]{1}[\d]{2}[AaBbCcDd]{1}$/;
var pattern3 = /^[54]{1}[12345]{1}[\d]{2}[YyZz]{1}$/;

if (!obj.match(pattern1) || !obj.match(pattern2) || !obj.match(pattern3)) {
alert("Doesn't match!");
return false;
}

No comments: