Example of using Regular Expressions for syntax checking in JavaScript

Q

Example of using Regular Expressions for syntax checking in JavaScript

✍: Guest

A


...
var re = new RegExp("^(&[A-Za-z_0-9]{1,}=[A-Za-z_0-9]{1,})*$");
var text = myWidget.value;
var OK = re.test(text);
if( ! OK ) {
alert("The extra parameters need some work.\r\n Should be something like: \"&a=1&c=4\"");
}

2008-05-13, 5976👍, 0💬