[SalesForce] Validation Rule on Phone Field to allow only Numbers or Blank

I wanted to write a validation rule for default Phone field.

AND( 
    NOT(ISBLANK( Phone )), 
    NOT(ISNUMBER( Phone )) 
)

it works fine but allows only 9 digits.
What could be the problem?
When i Deactivate this validation rule, it accepts more than 10 digits or alphabets.
Why is the Number restriction enforced?

Best Answer

Ten digit numbers are automatically reformatted as '(###) ###-####', which means that ISNUMBER will return false (because it has spaces, parentheses, and a hyphen). Also, when you see the documentation, you'll see it also supports numbers like 2e2 or 123.123, which are both numbers, but not phone numbers.

So, what you're probably looking for, for a start, is two specific patterns that will match US and other numbers:

AND(NOT(REGEX(Phone,'\\d*')), NOT(REGEX(Phone,'\\(\\d{3}\\) \\d{3}-\\d{4}')))

You'll want to experiment with REGEX to determine which rule(s) you'd like to follow.