驗證Regex 替換,驗證Regex

來源:互聯網
上載者:User

驗證Regex 替換,驗證Regex

var t_tPipeId = $("#tPipeId").val();t_tPipeId = $.trim(t_tPipeId);t_tPipeId = t_tPipeId.replace(/\-/g, "_n");//特殊字元除外"-"
var t_tPipeLen = $("#tPipeLen").val();t_tPipeLen = $.trim(t_tPipeLen);
var t_tColor = $("#tColor").val();t_tColor = $.trim(t_tColor);t_tColor = t_tColor.replace("#","");//特殊字元#用%23替代


var reg = /^\d+$/;//請填寫數字

var reg2 = /^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]+$/;//不能輸入特殊字元


if(t_tpipeSn == "" || t_tPipeId == "" || t_tPipeLen == "" || t_tPipeDia == "" || t_tPipeMat == "" || t_tLvl == "" || t_tColor == ""){
$("#msgInfo").html("不可為空!");
return false;
}else if(!reg.test(t_tPipeLen) || !reg.test(t_tPipeDia) || !reg.test(t_tPipeMat) || !reg.test(t_tLvl)){
$("#msgInfo").html("請填寫數字!");
return false;
}else if(!reg2.test(t_tPipeId)){
$("#msgInfo").html("不能輸入特殊字元!");
return false;

}


var s = "abcdefgbb";

s = s.replace("b", "n");//將b替換成n,只能替換一次

s = s.replace(/\b/g, "n");// 將所有的b替換成n



郵箱驗證Regex

^是匹配的字元開頭,
\w匹配的是字母,數字,底線,漢字,
+是匹配一次或多次(就是最少一次),
\.是匹配的 . (因為.在正則中匹配除分行符號以外的任一字元),所以如果需要.在字串中出現的話就加一個\ ,這個是轉義符
*匹配的是重複零次或更多次
@是匹配字串中必須出現的字元
$是字串結尾
本人手寫,希望給分,哈哈
 
驗證數位Regex???

^-?[1-9]{1}\d{0,2}(,\d{3})*?$
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.