parsley.js telephone digits input validating with spaces

别说谁变了你拦得住时间么 提交于 2019-12-05 07:19:18

That's a great answer, but it's a bit too narrow for my needs. Input field should be tolerant of all potential inputs – periods, hyphens, parentheses, spaces in unexpected places, plus signs for international folk – and using this document from Microsoft detailing what numbers IE11 should accept, I've come up with this:

data-parsley-pattern="^[\d\+\-\.\(\)\/\s]*$"

Every number in that list passes the test with flying colours. Enjoy!

Luís Cruz

If you want your input to accept a string like "nnnn nnnn nnnn" you should use a regular expression. For example, you can use the following HTML:

<input type="text" name="phone" value="" data-parsley-pattern="^\d{4} \d{4} \d{4}$" />

With this pattern the input will only be valid when you have fourdigits«space»fourdigits«space»fourdigits You can test or tweak the regular expression and test it here: http://regexpal.com/

If you will use this pattern multiple times in your project I suggest you create a custom validator (see http://parsleyjs.org/doc/index.html#psly-validators-craft)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!