文本框验证检查 [英] Text box validation check
本文介绍了文本框验证检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果文本框以< ;?开头,如何显示警告消息或<!或文本包含类似< text>使用java脚本或jquery。
我尝试过:
尝试使用正则表达式,但它无法正常工作。
How to display alert message if text box starts with <? or <! or text contains like <text> using java script or jquery.
What I have tried:
Tried using regular expression but its not working properly.
推荐答案
试试这个
Try this
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script>
function validateFun() {
debugger;
var txt = document.getElementById('txt1');
var value = txt.value.trim();
var itemsToValidate = [];
itemsToValidate.push('<&');
itemsToValidate.push('<!');
for (var i = 0; i < itemsToValidate.length; i++) {
if (value.startsWith(itemsToValidate[i])) {
alert('Your message');
return false;
}
}
return true;
}
</script>
</head>
<body>
<input type="text" id="txt1" value=" " />
<button onclick="return validateFun();">sub</button>
</body>
</html>
这篇关于文本框验证检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文