I need regex to match an alphanumeric string exact 11 characters long but the value must contain at least both 1 character and 1 number.
Used a combination of Regex for alphanumeric with at least 1 number and 1 character
i.e. /^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/
and What is the regex to match an alphanumeric 6 character string?
i.e. ^[a-zA-Z0-9]{6,}$
by using OR (||) operator like this
//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
but it would be great if i get it in one regex.