简体   繁体   English

正则表达式([A-Za-z] *)是否匹配数字和特殊字符?

[英]Regular expression ([A-Za-z]*) matches digits and special characters?

i need to validate a text fiel in my application. 我需要在我的应用程序中验证文本字段。 this cant contain neither digit nor special char so i tried this regex: [A-Za-z]* The problem is that this regex doesn't work when i put a digit or a special char in the middle or at the end of the String. 这个不能同时包含数字和特殊字符,所以我尝试了此正则表达式:[A-Za-z] *问题是当我在中间或末尾放置数字或特殊字符时,此正则表达式不起作用串。

You should use it like this: 您应该这样使用它:

^[A-Za-z]+$

to match text (1 or more in length) containing ASCII letters only. 匹配仅包含ASCII字母的文本(长度为1个或更多)。

继续尝试^[A-Za-z]*$

You could use the following Regex: 您可以使用以下正则表达式:

Pattern p = Pattern.compile("^[A-Za-z]*$");

See a list of regex-specs on http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html 请参见http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html上的正则表达式规范列表

The pattern you describe will never work. 您描述的模式将永远无法使用。 Without the begin and end bonds the pattern will look for a substring that matches. 没有开始键和结束键,模式将寻找匹配的子字符串。 Since an empty string is also allowed (star means 0 or more characters), one can simply use the empty string anywhere. 由于还允许使用空字符串(星号表示0个或更多字符),因此您可以在任何地方简单地使用空字符串。

您正在检查是否可以帮助我验证日期时间类型YYYY-MM-DDThh:mm:ss.sssZ或YYYY-MM-DD

^(((19|20)[0-9][0-9])-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01]))|(((19|20)[0-9][0-9])-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])T([01]?[0-9])|([2][0123]):([012345]?[0-9]):([012345]?[0-9])\.([0-9][0-9][0-9][Z]))$

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

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