开发者

validation using html5 pattern attribute for pin

开发者 https://www.devze.com 2023-02-25 09:28 出处:网络
I am trying to validate pin number ( 6 digits always). I am using, [0-9]{6} Which does the job but it makes field compulsory.

I am trying to validate pin number ( 6 digits always). I am using,

[0-9]{6}

Which does the job but it makes field compulsory.

How to make 开发者_如何学Goit optional?


^([0-9]{6})?$

^ ist string start, $ is string end, and the ()? says: My content exactly once or nothing.

However, if I read the spec correctly, and a quick test in FF4 doesn't deceive me, this might not be necessary, as long as you don't add the required attribute, too (in which case it would be an error).

0

精彩评论

暂无评论...
验证码 换一张
取 消