Minimum and maximum length of the form field

Is there a way to set the minimum and maximum length of 15 numbers (only numbers) in my form field?

I tried:

pattern".{15,15}"

Here's the JSFiddle: http://jsfiddle.net/aScpD/2/

+3
source share
3 answers

Try

\d → for numbers

Screenshot

pattern="\d{15,15}"


Update on s1lence comments
pattern="\d{15}"


Update to install Custom Validation Message

Add this attribute to the input field.

oninvalid="this.setCustomValidity('15 digit number needed')"

Use as a comment on Yucca C. Corpel (check the script above for a working demo)

title="Exactly 15 digits"
+6
source

Try the following:

pattern = /[0-9]{15}/
  • [0-9] (, \d, \d ) :. , JS, Perl RegEx.

  • {15} {15, 15}.

0

You can also do it like this.

<input title="requires exactly 15 digits" maxlength="15" pattern=".{15}" required />

Demo

0
source

All Articles