In Jquery i want a function which should not allow special character.
I want some thing like this:
function CheckFileName(Name) {
$('span.error-keyup-2').remove();
var inputVal = $(this).val();
var characterReg = /^\s*[a-zA-Z0-9,\s]+\s*$/;
if (!characterReg.test(Name)) {
$(this).after('<span class="error error-keyup-2">No special characters allowed.</span>');
return false;
}
}
I know its not work.there is not any thing like test.But unable to use regex pattern in jquery.Thanks.
There is a test() method of a regular expression object so your code will work.
pattern.test(string)returns true if string matches given pattern.