導航:首頁 > 編程語言 > java正則表達式驗證是否包含

java正則表達式驗證是否包含

發布時間:2024-03-27 03:35:49

java正則表達式如何判斷字元串中是否含有特殊字元

public class Test2 {
public static void main(String[] args){
String s = "123asdqwe__123 rew-trafgds";
if(s.replaceAll("[a-z]*[A-Z]*\\d*-*_*\\s*", "").length()==0)
System.out.println("input correct");
else
System.out.println("input incorrect");
}
}

② java 怎麼判斷一個字元串中是否包含數字

網路上已復經方製法了,參考如下:
1.用java自帶的函數
public
static
boolean
isnumeric(string
str){
for
(int
i
=
0;
i
<
str.length();
i++){
system.out.println(str.charat(i));
if
(!character.isdigit(str.charat(i))){
return
false;
}
}
return
true;
}

③ java正則表達式判斷一個字元前是否有一個字元

java使用match和pattern來實現判斷字元串是否不含有某個字元,實例如下:
/**
* 判斷字元串是否數值
* @param str
* @return true:是數值 ;false:不是數值
* @author:WD_SUHUAFU
*/
private boolean isNumber(String str)
{
Pattern pattern = Pattern.compile("^[0-9]+(.[0-9]*)?$");
Matcher match=pattern.matcher(str);
return match.matches();
}

④ Java 判斷字元串是否含有所有特殊符號

String ss = "Axs123a";
boolean a = ss.matches("[A-Za-z0-9\\u4e00-\\u9fa5]+");
System.out.println(a);
正則表達式:
中文、英文、數字但不包括下劃線等符號:^[\u4E00-\u9FA5A-Za-z0-9]+$
\u4E00-\u9FA5 匹配所有漢字
A-Za-z0-9 匹配 帶小寫字母和數字
+ 表示至少匹配一次,可以匹配無數次,空字元串默認返回false
^ 正則表達式開始符 $ 正則表達式結束符

⑤ java中如何用正則表達式判斷一個字元串中是否包含0-9的數字

// 判斷一個字元串是否都為數字
public boolean isDigit(String strNum) {
return strNum.matches("[0-9]{1,}");
}

// 判斷一個字元串是否都為數字
public boolean isDigit(String strNum) {
Pattern pattern = Pattern.compile("[0-9]{1,}");
Matcher matcher = pattern.matcher((CharSequence) strNum);
return matcher.matches();
}

//截取數字
public String getNumbers(String content) {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}

// 截取非數字
public String splitNotNumber(String content) {
Pattern pattern = Pattern.compile("\\D+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 判斷一個字元串是否含有數字
public boolean hasDigit(String content) {
boolean flag = false;
Pattern p = Pattern.compile(".*\\d+.*");
Matcher m = p.matcher(content);
if (m.matches())
flag = true;
return flag;
}

閱讀全文

與java正則表達式驗證是否包含相關的資料

熱點內容
機械類專業要學什麼編程 瀏覽:89
SQL中打開excel文件 瀏覽:468
藍牙可以傳word文件嗎 瀏覽:65
三星能自己升級系統嗎 瀏覽:265
12款新福克斯手動擋bcm升級 瀏覽:330
js內容尾部增加內容 瀏覽:803
sqlldr控制文件詳解 瀏覽:614
做界面用哪個編程語言 瀏覽:942
怎麼把網站打包成蘋果手機 瀏覽:913
補丁在哪個文件夾 瀏覽:170
類似安全文件的軟體 瀏覽:723
為什麼編程要學這門語言 瀏覽:678
網卡的配置文件目錄 瀏覽:960
計算器單片機編程叫什麼 瀏覽:736
網站編輯需要會什麼 瀏覽:622
單片機程序計數器的功能 瀏覽:917
網路攝像頭怎麼接虛擬儲存器 瀏覽:84
好壓IMG壓縮文件轉換成光碟 瀏覽:588
前端json格式如何排序 瀏覽:821
ocx實現選擇保存文件 瀏覽:986

友情鏈接