0

i have following method of Jquery Validation:

jQuery.validator.addMethod("alpha", function(value, element) {
    return this.optional(element) || value == value.match(/^[a-zA-Z]+$/);
},"Only Characters Allowed.");

Now i am having problem that if i add a space between my name words it gives me error can anyone tell me what will be the Regex for checking a name which may have character inputs of A-Z,a-Z and also a space.

4

2 回答 2

3

全名不规则。我建议不要进行验​​证,而不要检查它是否为空。

不同文化中的不同名称看起来可能非常不同。您的模式中不包含大量特殊字符,它们很可能存在于名称中。即使是很常见的。

考虑

  • 奥布莱恩
  • 弗朗索瓦
  • 林内
  • שְׂרוּ
于 2012-08-23T13:11:11.340 回答
1
$("#ValuationName").bind("keypress", function (event) {
    if (event.charCode!=0) {
        var regex = new RegExp("^[a-zA-Z ]+$");
        var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
        if (!regex.test(key)) {
            event.preventDefault();
            return false;
        }
    }
});

Try This
于 2013-05-06T08:59:41.903 回答