How to check for alphanumeric characters

前端 未结 5 1455
南笙
南笙 2020-12-08 22:58

I\'m writing a custom method for a jQuery plugin:

jQuery.validator.addMethod(\"alphanumeric\", function(value, element) {
        return this.optional(elemen         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-08 23:26

    If you want to use Spanish chars in your alphanumeric validation you can use this:

    jQuery.validator.addMethod("alphanumeric", function(value, element) {
        return this.optional(element) || /^[a-zA-Z0-9áéíóúÁÉÍÓÚÑñ ]+$/.test(value);
    });
    

    I also added a blank space to let users add words

提交回复
热议问题