I am trying to interrupt a form submission to test field for alphanumeric characters. After googling i found a lot of this implementation for regex that everyone claims works great...
if( !jQuery('input[name=myUsername]').val().test(/^[a-zA-Z0-9]+/) ) {
alert('ERROR: Your username contains invalid characters. Please use numbers and letters only. No spaces, no punctuation.');
jQuery('input[name=myUsername]').focus();
return false;
}
However, this ONLY returns false and creates an alert if the value STARTS with a non-alphanumeric character. If i enter "bo$$" it allows it as alphanumeric even tho $ is not an alphanumeric character... If i enter "$$ob" it fails and alerts.
How do i fix this so that it will fail for ANY invalid character in the entire value? I've tried .match() instead of .test() but same issue im assuming it's something in the regex that is wrong