1
0
-1

We need a input field which only accepts 8 digit number. We could not restrict the length and the numbers starting with zero gives validation errors when we  try a text field with "Number" as input type.

So, we changed the input type as "Telephone" which works with numbers with leading zeros and can restrict the length. But this field let us keying in alphabets.

Please help how we can restrict entering alphabets in Text Field when Input type is "Telephone".

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      I would argue that you don't want to impose this type of restriction for the following reasons:

      • Humans want to record phone numbers with all sorts of characters: ( ) - + ext.
      • Putting in too much validation in a phone number causes friction (and contributes to abandonment)
      • The applicant is more likely to type it in incorrectly, if they are forced to type it in a different way than what they are used to.
      • Copy paste may drop digits
      • What is the cost to the backoffice for inconsistency in data? (Arguably, nothing)
      • You could spend months trying to get your validation exactly correct. No one has ever cracked this problem for all cases.


        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi,

        This might be a rather brute-force approach, but you could put something like this in your Form Load rule:

            jQuery('#textField').keypress(function (event) {
                return event.keyCode < 32 || (event.keyCode >= 48 && event.keyCode <= 57);
            });

        You could adapt it to allow other characters such as (, ), - or space.

        You could also apply this to a plain 'Text' type input field, which might have wider browser support than 'tel'.

          CommentAdd your comment...