仅输入3个字符和3个星号 [英] Input only 3 characters and 3 asterisk

查看:71
本文介绍了仅输入3个字符和3个星号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对代码进行编程,以仅允许用户输入3个星号或3个字母.这2个不同的字符不能一起使用.我该怎么办?

I need to program my code to only let users input 3 asterisk or 3 alphabets. The 2 different characters can't be used together. How can I do that?

例如,用户可以输入***或AAA

For instance, user can input *** or AAA

我在这里查找了一些东西,得到的只是regEx = \ d {3} [a-zA-Z] {3} $/;

I looked up some stuff on here and all I got was regEx = \d{3}[a-zA-Z]{3}$/;

这对我不起作用.

推荐答案

您可以使用此regex :

^(?:\*{3}|[A-Za-z]{3})$

在字符串^的开头和字符串$的结尾之间,您可以指定3倍* \*{3}| 3倍[A-Za-z]{3}.

Between the beginning of the string ^ and the end of the string$, you can specify 3 times an * \*{3} or | 3 times [A-Za-z]{3}.

(?:非捕获组.

这篇关于仅输入3个字符和3个星号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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