How to validate a form field in format - 00.000.000.0-000.000

121 Views Asked by At

I am creating a form in PHP and in my form I have a field "TAX ID". This field should have value in this format only - "00.000.000.0-000.000"

Any suggestion how to achieve validation in this format for "TAX ID" field ??

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

I recommend you to use regex https://www.w3schools.com/php/php_regex.asp

<?php
$str = "Visit W3Schools";
$pattern = "/w3schools/i";
echo preg_match($pattern, $str); //this is true
?>

for example

/[0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9]-[0-9][0-9][0-9].[0-9][0-9][0-9]/