導航:首頁 > 編程語言 > 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正則表達式驗證是否包含相關的資料

熱點內容
任命文件人字多少號 瀏覽:27
如何給桌面的文件自動填寫序號 瀏覽:349
壓縮文件JPG重命名 瀏覽:487
vivox7怎麼隱藏文件 瀏覽:340
官網買蘋果好處 瀏覽:153
直播app源碼如何搭建 瀏覽:31
c盤系統文件包介紹圖片 瀏覽:856
linuxopt主要存哪些文件 瀏覽:924
jsdate天數 瀏覽:930
qq空間怎樣發視頻文件在哪裡找 瀏覽:208
nrf2401收發程序 瀏覽:498
哪個網站看新聞最好 瀏覽:944
找到文件夾並清除linux 瀏覽:82
蘋果app不安全怎麼辦 瀏覽:1000
電腦桌面文件收集軟體推薦 瀏覽:317
桌面的文件夾不能刪除不了怎麼辦 瀏覽:724
什麼是手機溫控文件 瀏覽:840
廣東農信app怎麼更改預留手機號碼 瀏覽:241
cdm打開隱藏文件夾 瀏覽:320
貝殼app房子為什麼偶爾不顯示 瀏覽:4

友情鏈接