本文介绍了如何在javascript中验证接受数字和字母但不应该只接受数字和特殊字符“/”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何在javascript中验证接受数字和字母但不应仅接受数字和特殊字符/示例:它可以是12/90,annanagar但它不应该是12 /或 12..任何人都可以帮助我在javascript中执行此操作 我试过的代码: var addresspat = / ^( @ [^ \d\ /])$ /; var address = document.getElementById( <%= txtAddr.ClientID%>)。 value ; var matchArray = address.match(addresspat); if (matchArray == null ) {} else { alert( 输入正确的地址); document.getElementById( <%= txtAddr.ClientID%>)。焦点(); return false ; } 解决方案 /; var address = document.getElementById( <%= txtAddr.ClientID%>)。 value ; var matchArray = address.match(addresspat); if (matchArray == null ) {} else { alert( 输入正确的地址); document.getElementById( <%= txtAddr.ClientID%>)。焦点(); return false ; } 你好Nityasri, 你的地址是非常重要的必须从数字开始,然后是斜线,然后是数字?如果是,请尝试使用 var PAT_CHECK = /(\d+\/\d+).*/g var ret = val.match(PAT_CHECK); if (ret == null ) alert( 地址无效!); 问候, how to validate in javascript to accept numbers and alphabets but should not accept only numbers and special character "/" example:it can be of "12/90,annanagar" but it should not be as "12/" or "12"..can anyone help me to do this in javascriptcode i tried:var addresspat=/^(@"[^\d\/]")$/; var address=document.getElementById("<%=txtAddr.ClientID%>").value; var matchArray = address.match(addresspat); if (matchArray == null) { } else{ alert("Enter The Correct Address"); document.getElementById("<%=txtAddr.ClientID%>").focus(); return false; } 解决方案 /; var address=document.getElementById("<%=txtAddr.ClientID%>").value; var matchArray = address.match(addresspat); if (matchArray == null) { } else{ alert("Enter The Correct Address"); document.getElementById("<%=txtAddr.ClientID%>").focus(); return false; }Hello Nityasri,Is it very much essentials that your address must start with numbers followed by a slash then numbers? If so then try with var PAT_CHECK = /(\d+\/\d+).*/gvar ret = val.match(PAT_CHECK);if (ret == null) alert("Invalid address!");Regards, 这篇关于如何在javascript中验证接受数字和字母但不应该只接受数字和特殊字符“/”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 06:59