Zach Long (Customer) asked a question.

Validate Phone Field in Sitefinity Form

We have a phone field in Sitefinity's form builder I'm trying to validate. I've tried using a textbox field set to Text type and Phone type but can't seem to get it working. The field will always freely let you enter whatever you want or say any phone number is invalid even if it's not. I've also tried several different regular expression validation patterns. How can I get this working?


  • Sabrie Nedzhip (Enso DX)

    Hi @Zach Long (Customer)​ ,

     

    I just tried it on a Sitefinity .NET Core project version 15.3. When selecting the field type to be Phone - it doesn't work. I had to add a regular expression in the form text field advanced settings.

     

    Here is the regular expression I used

    ^[+]{1}(?:[0-9\-()\/.\s]?){6,15}[0-9]{1}$

     

     

    image 

    image 

    I hope this helps.

     

    Regards,

    Sabrie

    Selected as Best
  • Sabrie Nedzhip (Enso DX)

    Hi @Zach Long (Customer)​ ,

     

    I just tried it on a Sitefinity .NET Core project version 15.3. When selecting the field type to be Phone - it doesn't work. I had to add a regular expression in the form text field advanced settings.

     

    Here is the regular expression I used

    ^[+]{1}(?:[0-9\-()\/.\s]?){6,15}[0-9]{1}$

     

     

    image 

    image 

    I hope this helps.

     

    Regards,

    Sabrie

    Selected as Best
  • Jonathan Read (Progress Software)

    @Zach Long (Customer)​ & @Sabrie Nedzhip (Enso DX)​ 

     

    If you take a look at the html spec for the type="tel" it doesn't really do anything without a pattern. Since phone numbers can differ so much it is best to use the Phone type along with a regular expression to meet your business needs. If you just use the "phone" option with Sitefinity it works the same as pointed out in the spec below ... good, bad or indifferent :/

     

    https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/tel