I want to do a phone validation but how do I validate the trace also in case the user places it?

1

This is what I have so far:

public static function ValidaFone($RegeEx)
{
 $RegeEx = preg_match('/^[0-9]{9,11,13}$/',$RegeEx);

      ........code.....
}
    
asked by anonymous 28.07.2017 / 16:18

1 answer

1

Phone traces can only be present in specific positions, right?

/^([0-9]{5}(-| )?[0-9]{4})$/

This regex reads as follows:

  • five numbers between zero and nine;
  • a space or hyphen, optional;
  • four numbers between zero and nine.

You can refine the expression to not allow, for example, phone numbers beginning with zero, or to include more snippets as an area code.

To understand any regular expression in JS, I recommend the link site. You can put an expression there and the site explains the excerpts.

    
28.07.2017 / 16:38