Javascript 使用引导按钮时发生验证错误
我不熟悉HTML/PHP/Javascript和引导框架 这是我的密码:Javascript 使用引导按钮时发生验证错误,javascript,php,jquery,html,twitter-bootstrap,Javascript,Php,Jquery,Html,Twitter Bootstrap,我不熟悉HTML/PHP/Javascript和引导框架 这是我的密码: <form name="Enquiry" method="post" action="query.php"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <h5>Choose search type:</h5> <div id
<form name="Enquiry" method="post" action="query.php">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<h5>Choose search type:</h5>
<div id="selector" class="btn-group">
<button type="button" name="Surname" class="btn btn-default active">Surname</button>
<button type="button" name="IDNumber" class="btn btn-default">ID Number</button>
<button type="button" name="FileNumber" class="btn btn-default">File Number</button>
</div>
<br>
<input id="searchbox" name="QD" type="text" size="20" maxlength="30" pattern="/[A-z]/g" title="0-Only alphabets allowed! No special characters or numbers. Please correct!">
<script>
$('#selector button').click(function() {
$(this).addClass('active').siblings().removeClass('active');
$getName = this.name;
switch ($getName) {
case "Surname":
document.getElementById('searchbox').value="";
document.getElementById('searchbox').maxLength="30";
document.getElementById('searchbox').pattern="/[A-z]/g";
document.getElementById('searchbox').title="1-Only alphabets and spaces allowed. Please correct!";
break;
case "IDNumber":
document.getElementById('searchbox').value="";
document.getElementById('searchbox').maxLength="13";
document.getElementById('searchbox').pattern="\d+";
document.getElementById('searchbox').title="2-Only numerical value allowed in the ID field! Please correct";
break;
case "FileNumber":
document.getElementById('searchbox').value="";
document.getElementById('searchbox').maxLength="5";
document.getElementById('searchbox').pattern="\d+";
document.getElementById('searchbox').title="3-Only numerical value allowed in the file number field! Please correct";
}
});
</script>
<input type="submit" class="btn btn-primary" name="search" value="Query">
</form>
完整代码位于:
我正在努力实现的目标:
根据用户按下的按钮,我使用regxp和maxlength等设置输入文本框的验证标准
我的问题是:
当我单击query按钮POST方法时,即使该值与regxp匹配,它仍然会抛出一个错误
有什么帮助和建议吗?Javascript允许正则表达式文本,所以您不需要引用您的行 更改此行: document.getElementById'searchbox'。模式=/[A-z]/g 为此: document.getElementById'searchbox'。模式=\[A-z]\g 这两行代码如下所示: document.getElementById'searchbox'。模式=\d+ 需要更改为:
document.getElementById'searchbox'。模式=\d+ 它到底在哪里抛出语法错误?当我使用它时,它在这边对我有效。