简体   繁体   English

正则表达式,用于以两个特殊字符开头的字符串

[英]Regex for starting a string with two special characters

I want to write a regular expression to force the user to fill an input with a 10 digit character that should start with 09. Like the followings: 我想编写一个正则表达式,以强制用户用应以09开头的10位字符填充输入。类似于以下内容:

0912345678
0968765432
.
.
.

I wrote th following to check the length: 我写了以下内容来检查长度:

[StringLength(10)]
[MinLength(10)]

Now I dont know how to check that its started with 09. 现在我不知道如何检查其以09开头。

Thanks for any idea. 感谢您的任何想法。

Try this regex: 试试这个正则表达式:

^09\d{8}$

Explanation: 说明:

  • ^ - Beginning of the string ^ -字符串的开头
  • 09 - Matches the digits 09 literally 09 -匹配数字09字面上
  • \\d{8} - Matches exactly 8 digits \\d{8} - 精确匹配8位数字
  • $ - End of the string $ -字符串结尾

Live demo 现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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