1

I want to validate the field for US format phone number(478-857-4578). I used the below code, it works fine for all but one scenario.

If I enter only 4 digit number or below than, the error message

The validation formula has evaluated to an error

is displayed.

But for all other wrong inputs, my custom error message

Please enter phone number in 214-587-5485 format

is displayed.

I wanted to display my custom error message for all invalid inputs. Do I need to change anything in formula?

Formula:

=AND(
LEN([num])=12,
    IF(ISERROR(FIND("-", [num],4)),
        FALSE,
        (FIND("-", [num], 4) = 4)
    ),
    IF(ISERROR(FIND("-", [num],8)),
        FALSE,
        (FIND("-", [num], 8) = 8)
    ),
    IF(ISERROR(1*CONCATENATE(MID([num], 1, 3), MID([num], 5, 3), MID([num], 9, 4))),
        FALSE,
        AND(
            1*CONCATENATE(MID([num], 1, 3), MID([num], 5, 3), MID([num], 9, 4)) > 1000000000,
            1*MID([num], 1, 3) <> 911,
            1*MID([num], 5, 3) <> 911
        )
    )
)

1 Answer 1

0

This is not validation, but you can use input mask by adding jquery on newform of list

Below is the script:

<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript" ></script>
<script language="javascript" src="http://jquery-joshbush.googlecode.com/files/jquery.maskedinput-1.2.2.min.js" type="text/javascript" ></script>
<script language="javascript" type="text/javascript">
jQuery(function($){
   $("input[title='Phone']").mask("(999) 999-9999? Ext.99999");
});
</script>

For your requirement, you can replace with below line:

$("input[title='Phone']").mask("999-999-9999");

For reference: Input Mask on Textbox

1
  • This isn't an answer to the question and I don't think it will work in most scenarios today anyway.
    – Tom Resing
    Commented Jun 20, 2022 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.