parsley.js telephone digits input validating with spaces

Dave picture Dave · Apr 12, 2014 · Viewed 19.3k times · Source

I have an input for telephone number.

I would like to write this format: 0175 6565 6262 (with spaces). But if write with " " spaces so get error and I write without spaces so get not error.

Here my HTML Input:

<input type="text" data-parsley-minlength="6" data-parsley-minlength-message="minlength six number" data-parsley-type="digits" data-parsley-type-message="only numbers" class="input_text" value="">

Hope someone can help me?

Answer

ghettosoak picture ghettosoak · Apr 16, 2015

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!