Javascript Regex确保最后3个字符是数字?

时间:2012-02-28 21:42:42

标签: javascript regex

如何验证字符串以完全三位数结尾?

有效的:

Hey-12-Therexx-111
001
xxx-5x444

无效:

Hey-12-Therexx-1111
Hey-12-Therexx-11
Hey-12-Therexx
12
112x

1 个答案:

答案 0 :(得分:9)

你可以写:

/(^|\D)\d{3}$/

表示“字符串开头或非数字字符,后跟三位数字,后跟字符串结尾”。