正则表达式,用于检查字符串是严格字母 [英] Regex for checking if a string is strictly alphanumeric

查看:193
本文介绍了正则表达式,用于检查字符串是严格字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查字符串只有数字和字母(字母数字)

How can i check if a string has only numbers and alphabets(alphanumerics)

推荐答案

考虑要检查ASCII字母数字字符,试试这个^ [A-ZA-Z0-9] * $,使用正则表达式中的 String.matches(正则表达式)将返回true,如果它是字母数字否则将返回false。

Considering you want to check for ASCII Alphanumeric characters, Try this "^[a-zA-Z0-9]*$", use this RegEx in String.matches(Regex) it will return true if it is alphanumeric else it will return false.

public boolean isAlphaNumeric(String s){
    String pattern= "^[a-zA-Z0-9]*$";
        if(s.matches(pattern)){
            return true;
        }
        return false;   
}

这将有助于了解更多详细的正则表达式读<一href="http://www.vogella.com/articles/JavaRegularEx$p$pssions/article.html">http://www.vogella.com/articles/JavaRegularEx$p$pssions/article.html

这篇关于正则表达式,用于检查字符串是严格字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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