简体   繁体   中英

Validation check on Mobile number in C# and JavaScript

I am trying to do a validation check on mobile number from both C# code and Javascript.

Following should be validated OK:

  • Length equal to 5 or 8+
  • Can start with +XXxxxx
  • Can start with 00xxxxxxx

I tried using:

C# code:

@"(^((([0-9]{5})|((\+[0-9]{2})[0-9]+)|((00[0-9]{2})[0-9]+))|((([0-9]{8,})|((\+[0-9]{2})[0-9]+)|((00[0-9]{2})[0-9]+))))$)"

JavaScript:

/^((([0-9]{5})|(((00[0-9]{2})|(\+?[0-9]{2}))[0-9]+))|(([0-9]{8})|(((00[0-9]{2})|(\+?[0-9]{2}))[0-9]+)))$/

With these expressions I am able to validate for 1st and last requirement but not the 2nd one (+XXxxxx).

Please help me out on this issue.

use the OR option in the regular expression

Sample:

(\+XX)|(00)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM