0

我需要为特定类型的数字和字母组合验证表单字段:

  • 前四位是字母
  • 下一个数字为零
  • 接下来的 6 位数字是数字

例如
IBKL 0 001084

4

1 回答 1

0

假设您的验证是客户端:

前四位是字母,下一位是零,后六位是数字

紧凑测试:

/[a-zA-Z]{4}\s?0\s?[0-9]{6}\s?$/.test("IBKL 0 001084 ");
/[a-zA-Z]{4}\s?0\s?[0-9]{6}\s?$/.test("IBKL 0 001084");
/[a-zA-Z]{4}\s?0\s?[0-9]{6}\s?$/.test("IBKL0001084");

详细测试:

var first_four = "[a-zA-Z]{4}",  zero = "0",  next_six = "[0-9]{6}", space_maybe = "\\s?", end = "$";

RegExp(first_four + space_maybe + zero + space_maybe + next_six + space_maybe + end).test("IBKL 0 001084 ");

RegExp(first_four + space_maybe + zero + space_maybe + next_six + space_maybe + end).test("IBKL 0 001084");

RegExp(first_four + space_maybe + zero + space_maybe + next_six + space_maybe + end).test("IBKL0001084");
于 2013-09-04T15:18:57.233 回答