【问题标题】:Validate that string contains only alphabets [duplicate]验证字符串仅包含字母[重复]
【发布时间】:2015-10-12 05:49:41
【问题描述】:

我想验证字符串并确保字符串只包含字母。

这是我的程序,其他部分正在打印

String myString = "hellothisisastring";
        String reg="[a-zA-Z]";

    if(myString.matches(reg)) 
        { 
        System.out.println("Yep!"); 
        } 
        else 
        { 
    System.out.println("Nope!"); 
        }

【问题讨论】:

    标签: java


    【解决方案1】:

    尝试改变你的正则表达式

    String reg="[a-zA-Z]+";
    

    + 将确保它匹配字符串一次和多次。

    【讨论】:

      猜你喜欢
      • 2012-09-07
      • 1970-01-01
      • 2010-11-13
      • 2014-09-11
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多