gpt4 book ai didi

javascript - 仅验证结尾字母

转载 作者:行者123 更新时间:2023-11-29 21:55:24 25 4
gpt4 key购买 nike

我也想验证用户将要输入的单词末尾的结尾“uu”、“ha”和“cross”……请参阅“脚本”标签中的“//”了解我的意思:)

这是我的 html 表单:

<form name="myForm" action="haha.php" onsubmit="return validateForm()" method="post">
<p id="text">Something: </p>
<input type="text" name="form" id="box" >
<input type="submit" value="Submit" id="but" >
</form>

<p id="check"></p>

还有我的java脚本验证...

function validateForm() {
if( document.myForm.form.value == "" ) {
document.getElementById('check').innerHTML = 'Please fill in the form:) ';
return false;
}

//ok so here's an example of what I'm trying to achieve...
if( document.myForm.form.value == endings "uu" "ha" cross" ) --//please correct- endings "uu" "ha" cross" -- {
return true;
}
}

最佳答案

尝试使用正则表达式来测试以给定子字符串之一结尾的字符串:

if (/(uu|ha|cross)$/.test(document.myForm.form.value)) {
return true;
}

关于javascript - 仅验证结尾字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26661536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com