I am using Jquery Validation.
Currently, I have a textfield. How can I prompt an alert when user type in 0 or any other symbols as the first character in the field?
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Please check your input."
);
$("#Textbox").rules("add", { regex: "^[a-zA-Z'.\\s]{1,40}$" })
Just looking at the regex, if all you want is to prevent the first character from being a zero and nothing else, it should be
To exclude symbols as well you can either add them to the list of prohibited characters
or specify the characters which are allowed. In this case, lower and uppercase letters, the numbers 1-9, an apostrophe, period or a space