English 中文(简体)
NI号码验证Jquery
原标题:NI Number Validation Jquery
$.validator.addMethod(
    "ninumber",
    function(value, element) {
        return this.optional(element)
          || /^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$/.test(value);
    },
    "Please enter a valid NI Number."
);

有人能发现代码示例中的任何问题吗?这对我来说似乎很好,但正确的值仍然显示为有错误。我正在使用jQuery验证插件来添加NI编号的方法。

最佳回答

它不允许有空间,所以你需要先去掉这些空间。我刚刚检查过,它验证了我的NI号码,但没有空格。

所以,你可能想要这样的东西:

/^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$/.test(value.replace(/s/g,   ));

如果您真的想将其保留为一行验证。就我个人而言,我会重新格式化/重构:

$.validator.addMethod("ninumber", function(value, element) {
  var regexp = /^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$/;
  var strippedValue = value.replace(/s/g,   );
  return this.optional(element) || regexp.test(strippedValue);
},  "Please enter a valid NI Number.");
问题回答

暂无回答




相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签