Evaluation for non-blank input but allowing for blank spaces
I'm validating for non-blank input, but I am allowing for spaces, so that typical English can be input.
I have this:
jQuery.valid开发者_JAVA技巧ator.addMethod("alphanumeric", function(value, element) {
return this.optional(element) || (/^[a-zA-Z0-9]+/.test(value));
});
Which will accept strings that have no spaces, otherwise it will not accept them.
Ex: It will accept Stack
or Overflow
but not Stack Overflow
I want to check for "at least one alphanumeric character somewhere". How may I go about this?
Note: If I am going about this in a conceptually inefficient way, please correct me, surely there is a standardized way of validating like this.
jQuery.validator.addMethod("alphanumeric", function(value, element) {
return this.optional(element) || (/^[a-zA-Z0-9]{1}([a-zA-Z0-9]*| [a-zA-Z0-9]+)*$/.test(value));
});
Must be this ;)
Edit: RegExp missing /
精彩评论