skip to Main Content

The phone number should start with 0 followed by 6 or 7 and should contain 10 digits only

Here are some sample phone numbers

0754758644 ,0621165600

Here is what I tried

String pattern = r'(^(?:[0]9)?[0-9]{10,12}$)';

4

Answers


  1. Use this regex pattern –

    String pattern = r'([0][6,7]d{8})

    Login or Signup to reply.
  2. this regex should work for you:

    String pattern = r'(^0(6|7)d{8}$)'
    

    I limited the digits to 8, because the 0 and the 6/7 already take up two digits of the length. The {8} only limits the direct predecessor (the digits matcher d).

    find out more about this regex here: regex101

    Login or Signup to reply.
  3. String pattern = r'^(?:[+0][1-9])?[0-9]{10,12}$';
    RegExp regExp = new RegExp(patttern);
    
    regExp.hasMatch(value)
    

    or you can apply keyboardtype property to textfield or textformfield if you are not familiar with regExp

    Login or Signup to reply.
  4. You can match a zero, then either 6 or 7 using character class followed by 8 digits.

    For a match only, you can omit the capture group.

    String pattern = r'^0[67]d{8}$' 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search