Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
Validate Bangladeshi phone number with optional +88 or 01 preceeding 11 digits

I am using the following regular expression to validate an Indian phone number.

I want optional +88 or 01 before 11 digits of phone.

Here is what I am using:

string mobileNumber = "+8801000000000";
if (new Regex(@"^([01]|\+88)?\d{11}").IsMatch(mobileNumber)){
    MessageBox.Show("Mobile number is valide", "All information is required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else{
     MessageBox.Show("Mobile number is not valide", "All information is required", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

How can I do it?

UPDATE

If I write mobile no. preceding 01, for more than 11 digit it notify validation mgs(Not valid mobile no.!). Well I used, it fails when 13 digit. It alters validation mgs wrongly.

Here is my code:

<input type="text" placeholder="Enter bKash wallet number" 
  class="form-control" ng-model="BkashWalletNo" ng-disabled="AutoConfirmed" 
    name="BkashWalletNo" ng-pattern="/^(?:\+88|01)?\d{11}\r?$/" />
<p class="help-block" ng-show="form.BkashWalletNo.$error.pattern">Not valid mobile no.!</p>
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You may use any one of given solution to validate Bangladeshi mobile number.

regular expression 1:

/(^(\+88|0088)?(01){1}[3456789]{1}(\d){8})$/

regular expression 2

 /(^(\+8801|8801|01|008801))[1|3-9]{1}(\d){8}$/

regular expression 3

 (^([+]{1}[8]{2}|0088)?(01){1}[3-9]{1}\d{8})$

Allowed mobile number sample

+8801812598624

008801812598624

01812598624

01712598624

01672598624

01919598624

01419598624

01319598624

etc

over 4 years ago · Santiago Trujillo Relatório

0

I see you have tried but your regular expression is not accurate.

  1. Doesn't use an end-of-string anchor $ (so even "abc" at the end won't prevent IsMatch returning true )
  2. You are using 01 in square brackets, thus creating a character class, which means 0 or 1 .
  3. A capturing group is not necessary here, a non-capturing one is better for optional sub-patterns.
  4. As has been pointed out in the follow-up answers, the regex you are using doesn't actually meet all the requirements for Bangladeshi phone number, see Kobi's ^(?:\+?88|0088)?01[15-9]\d{8}$ answer.

To create a regular expression that validates a string that has " optional +88 , 0088 , or 01 preceding 11 digits ", you need something like:

 @"^(?:(?:\+|00)88|01)?\d{11}$"

Watch the RegexStorm demo

TO UPDATE

If you want to validate Bangladeshi phone numbers with this regular expression, nothing changes in the pattern (only \r? is totally redundant), but if you plan to allow 13 or 11 digits after +88 or 01 , you should use an alternation:

 ng-pattern="/^(?:(?:\+|00)88|01)?\d{11}$/"

See demo

In Angular:

 Validators.pattern('(?:(?:\\+|00)88|01)?\\d{11}') // or Validators.pattern(/^(?:(?:\+|00)88|01)?\d{11}$/)
over 4 years ago · Santiago Trujillo Relatório

0

A better answer can be found here: Validate Mobile number using regular expression

There is two good answer in this post. Summary of them

Solution-1: Using regular expression

Should be pretty simple:

^(?:\+?88|0088)?01[15-9]\d{8}$
  • ^ - From start of the string
  • (?:\+?88|0088)? - optional 88, which may begin in + or optional 0088
  • 01 - mandatory 01
  • [15-9] - "1 or 5 or 6 or 7 or 8 or 9"
  • \d{8} - 8 digits
  • $ - end of the string

Working example: http://rubular.com/r/BvnSXDOYF8

Solution-2: Using Library

Download this free library libphonenumber from Google. It's available for Java, C++ and Javascript, but there're also fork for PHP and, i believe, other languages.

+880 tells me that it's country code for Bangladesh. Let's try to validate example numbers with following code in Java:

String bdNumberStr = "8801711419556";
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
    //BD is default country code for Bangladesh (used for number without 880 at the begginning)
    PhoneNumber bdNumberProto = phoneUtil.parse(bdNumberStr, "BD");
} catch (NumberParseException e) {
    System.err.println("NumberParseException was thrown: " + e.toString());
}
boolean isValid = phoneUtil.isValidNumber(bdNumberProto); // returns true

That code will handle also numbers with spaces in it (for example "880 17 11 41 95 56"), or even with 00880 at the beggininng (+ is sometimes replaced with 00).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda