Monday, August 18, 2008

Nice Regexps

I've been doing some Javascript client-side form data entry validation lately. I wasn't interested in using a jQuery plugin because I frankly didn't trust that the plugin author would get it right. Besides, I can write my own plugin once I figure this out. Anyway, here's some need RegExps I found along the way:

Test for Alphanumeric

if (/\W/.test(s)) {
alert('That field is not alphanumeric.');
}


Test for Normal Full Name Structure

if ((!/^([a-z\x80-\xFF\'\.\-]+(. )?[ ]?)+$/i.test(sFull)) || (/\d/.test(sFull))) {
alert("The Full Name must be alphabetical and properly formatted (i.e., O'Malley Haven-Wilcox Jr.)";
}


Anyway, more can be found here, but they aren't all perfect and require testing:

http://regexlib.com/

No comments:

Post a Comment