Ticket T218137
Visible to All Users

Regular Expression for variable Mask

created 10 years ago

Dear all,

I know this is a bit much asked but please help me define a regex for a phone number mask. I just don't know how to do this.

I have a texteditor which should be able to support two different phone masks, with the user being able to fill in whatever applies

  1. 042 342 10 76
  2. 12423 342 10 76

Each number consists of 4 parts, as follows:

part1: 3-5 digits, if not all 5 digits are used no placeholder should be shown once the text edit looses focus (the displayed value should be just like 1)
part 2: always 3 digits
part 3 + 4: each always 2 digits

The best i was able to achieve was using a simple editor, but that resulted in 1) looking like: __042 342 10 76 or 042__ 342 10 76 when not edited, instead of 042 342 10 76.

Thank you so much for your help!

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hi Marc,

Try the following expression:

(\d{3})|(\d{4}) \d{3} \d{2} \d{2}

C#
this.textEdit1.Properties.Mask.EditMask = "(\\d{3})|(\\d{4}) \\d{3} \\d{2} \\d{2}"; this.textEdit1.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx; this.textEdit1.Properties.Mask.ShowPlaceHolders = false;

Let me know of your results.

    Comments (2)

      Dear Alisher,
      Thanks so much for your fast response. That helped a lot. I had to make a small adjustment as it didn't allow me to only provide 3 digits. It appears two brackets were unneccessary. This is my result which works:
      (\d{3}|\d{5}) \d{3} \d{2} \d{2}
      Thank you Alisher!!

      Alisher (DevExpress Support) 10 years ago

        You are always welcome! :)

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.