我需要验证特定类型的数字和字母组合的表单字段:
e.g。
IBKL 0 001084
答案 0 :(得分:0)
假设您的验证是客户端的:
前四位是字母,下一位是零,接下来的6位是数字
紧凑测试:
/[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");