You are viewing limited content. For full access, please sign in.

Question

Question

Limit field to 9 digits

asked on October 18, 2018 Show version history

How do I limit a number field to be only 9 digits? Thanks

 

Priya

0 0

Replies

replied on October 18, 2018

Hi Priya,

The number range should work be setting the max to 999,999,999 and/or the min if you allow negative numbers.

0 0
replied on October 18, 2018

Thanks. But, I want the user to be able to enter just 9 digits, not 8 or 10. It should accept just 9 digits.

 

Priya

0 0
replied on October 18, 2018

Ah ..

The easiest solution would be to use a single line text field with a regular expression: \d{9}

Add text (above/below) to indicate it must be 9 digits or a process error message.

 

0 0
replied on October 18, 2018

Does your input allow entries that start with leading 0's?
If not you could use a min and max on a number field, 111111111 and 999999999.

You can check a number field with a little jquery but I am not sure how you would actually 'enforce' the entry unless you made the field required and the script blanked the entry if it was not 9 digits:
 

  $('#q4 input').change(function() {
    if ( $(this).val().length !== 9 ) {
      alert("Number must be 9 digits");
      $('#q4 input').val('');
    }
  });

A reg exp on a text field seems the best bet.

0 0
replied on October 18, 2018

Thanks all.

Priya

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.