1
我需要正則表達式來匹配長度爲11個字符的字母數字字符串,但該值必須至少包含1個字符和1個數字。正則表達式的字母數字字符串,至少有1個數字和1個字符,固定長度爲11
通過使用OR(||)運算符這樣
//regex code
var str = "";
if ($.trim($("input[id$='txtBranchName']").val()) != "")
str = $.trim($("input[id$='txtBranchName']").val());
var reg_exp = /^(?:[0-9]+[a-z]|[a-z]+[0-9])[a-z0-9]*$/i; // /^[a-zA-Z0-9]{11,}$/;//^(\d)(?:\1+)?$/; // new RegExp('([0-9]){6}');
var reg_exp2 = /^[a-zA-Z0-9]{11,11}$/;
if (!reg_exp.test(str) || !reg_exp2.test(str)) {
$("span[id$='lblError']").css("color", "red");
$("span[id$='lblError']").html($("span[id$='lbl_PayeeInformation_IFSCNo']").html()).show();
$("input[id$='txtBranchName']").focus();
returned = false;
return false;
}
//end regex code
使用的
Regex for alphanumeric with at least 1 number and 1 character
即/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/
和What is the regex to match an alphanumeric 6 character string?
即^[a-zA-Z0-9]{6,}$
的組合
但如果我在一個正則表達式中得到它會很好。
它工作@Pranav,謝謝 –