Looking for help on a regex for JS and adding a few more characters. This is what it currently includes (I think):
- All alphanumeric characters
- space
- apostrophe
- period (dot)
- comma
- underscores and hyphens
My current regex here:
/^[\w-\.-\,\s-']+$/
Can it be formatted better? This is for a <input>
text field on a web form, and I'm open to additional suggestions or potential downfalls on my current statement.
Finally, how would I additionally include $
and &
and %
characters?
The JS that checks against my regex is this:
function has_error(el, type) {
var textReg = /^[\w-\.-\,\s-']+$/;
if ( el.val() == '' || (type=='text' && !textReg.test(el.val())) ) {
// apply error logic
return true;
} else {
// clear error logic
return false;
}
}