简体   繁体   English

以html格式自定义客户端正则表达式验证

[英]Custom clientside regex validation in an html form

I am trying to validate a form input type text. 我正在尝试验证表单输入类型的文本。 The value should be ending in ".tar.gz" and should have some keywords. 该值应以“ .tar.gz”结尾,并应包含一些关键字。 Anyways I have the regex ready, but I am stuck on how to validate this without pressing submit. 无论如何,我已经准备好了正则表达式,但是我坚持不使用提交就可以进行验证。 Kind of like how "pattern" attribute works. 有点像“模式”属性的工作方式。 Any suggestions? 有什么建议么? this is the row which needs to be validated and the submit button already has a function to disable the button after 1st click. 这是需要验证的行,并且第一次单击后,提交按钮已经具有禁用该按钮的功能。 as shown below. 如下所示。

<tr> <td>Suite Name</td> <td><input type='text' name='same' id='sname' title='Default suite name format: autosuite_<signum>_timestamp'/></td> </tr> 

<input type='submit' name='launch' id='launch' onclick='setTimeout(disableFunction, 1)' value='Launch'/><br>

You can use the String.search() method like: 您可以使用String.search()方法,例如:

var str = document.getElementById("yourinputelementid").value;
var n = str.search("regexpression");

Will return -1 if it doesn't exist or the index of the match if it does exist. 如果不存在则返回-1,如果存在则返回匹配的索引。 If you want to do validation without pressing submit call a method to test string onkeyup event of your input. 如果您想执行验证而不按Submit键,请调用一种方法来测试输入的字符串onkeyup事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM