jquery正則表達式驗證:驗證是否包含中文,字母,數字

需求說明:html

  前端頁面使用正則表達式驗證輸入的數據是否包含中文,字母,數字。前端

代碼說明:jquery

  這裏只介紹正則表達式,其餘部分的代碼不作介紹。若是有其餘須要自行修改便可。正則表達式

步驟一:創建一個頁面能夠是html、jsp等,引入jquery-3.2.1.min.js(其餘版本亦可)。jsp

步驟二:編寫正則表達式。測試

代碼部分以下:spa

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.2.1.min.js" ></script>
</head>
<body>

</body>
<script>
    //這裏默認頁面加載時驗證輸入數據
 $(function () { var value="1SSS-23測試"; if(isChinese(value)){ console.log("參數:符合驗證要求"); }else{ console.log("參數: 不符合驗證要求"); } }) //驗證是否包含中文,字母,數字@
    function isChinese(c) { var specialChar = "~!¥!…@#$%^&*() ()_+{}:\"<|、:>?-=[]?【】《》?:「『』;',./'vwxyz"; //var specialChar = "^[a-z0-9A-Z\u4e00-\u9fa5]+$";
        var index = specialChar.indexOf(c); if (index > -1) { return false; } else { var re = /^([A-Za-z]|[\u4E00-\u9FA5]|[0-9])+$/; return re.test(c); } } </script>
</html>
相關文章
相關標籤/搜索