如何在javascript中验证文本框的字母数字,连字符和斜杠 [英] How to validate textbox in javascript for alphnumeric, hyphen and slash

查看:61
本文介绍了如何在javascript中验证文本框的字母数字,连字符和斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证文本框(Bank Challan编号)只输入字母数字连字符和斜杠。

不允许连续连字符或斜杠。

喜欢_ /和/ _和_ _和//并且不允许使用空白<​​br />


我尝试过:



I want to validate textbox(Bank Challan number) to enter alphanumeric hyphen and slash only.
Consecutive hyphen or slash not allowed.
Like _/ and /_ and _ _ and // and whitespace not allowed

What I have tried:

re=/^[0-9a-zA-Z/ -]+$/;

                if( $('#<%=txt.ClientID%>').val().match(re))
                {
                    alert("valid");
                    
                }
                else {
  alert("not valid");
                }

推荐答案

/;

if


'' #<%= txt.ClientID%>')。val()。match(re))
{
alert(< span class =code-string> valid);

}
else {
alert( 无效);
}
('#<%=txt.ClientID%>').val().match(re)) { alert("valid"); } else { alert("not valid"); }


要对正则表达式进行测试,可以使用 test 方法在 RegExp

RegExp.prototype.test() - JavaScript | MDN [ ^ ]

To do the testing against the regex, you can use the test method on RegExp.
RegExp.prototype.test() - JavaScript | MDN[^]
if (re.test(


这篇关于如何在javascript中验证文本框的字母数字,连字符和斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆