正则表达式有ATLEAST 1个字符和1号 [英] Regex to have atleast 1 character and 1 number

查看:168
本文介绍了正则表达式有ATLEAST 1个字符和1号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个正则表达式,使得它的最小长度为8,最大长度为25,它应该至少包含1 [A-ZA-Z] 和至少1 [0-9]

I am trying to make a Regex such that it's min length is 8 and max length is 25 and it should contain at least 1 [A-Za-z] and at least 1 [0-9]

下面是我想出了:

Regex regex = new Regex("^.+${8,25}(?<=[A-Za-z])(?<=[0-9])");

var test = regex.IsMatch("testadasd9");

但它不工作。正如你可以看到我身后用正面看。任何帮助是AP preciated。

But it is not working. As you can see I am using positive look behind. Any help is appreciated.

推荐答案

您可以尝试下面的正则表达式匹配的最小长度为8,最大长度为25的字符串,也该字符串必须包含用于至少一个文字 [A-ZA-Z] 并且至少一个数字。

You could try the below regex to match a string of minimum length 8 and max length 25 and also the string must contain atleast one literal [A-Za-z] and atleast one digit.

^(?=.{8,25}$)(?=.*?[A-Za-z])(?=.*?[0-9]).*

演示

这篇关于正则表达式有ATLEAST 1个字符和1号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆