gpt4 book ai didi

jquery - 获取输入文本字段的值并将其子字符串化

转载 作者:太空宇宙 更新时间:2023-11-04 14:49:40 41 4
gpt4 key购买 nike

请访问我的第一个 fiddle :http://jsfiddle.net/vHLXX/

这是电话号码。输入字段,如果长度为 11(文本输入字段的值),则单击提交按钮时提示"is",否则提示“否”。

现在,如果第一个三个字符串不是 011,我想要警告“无效!”

我怎样才能得到这个(使用 jquery)?

这是 html:

<span>enter you mobile no.</span>
<input maxlength="11" size="11" type="text" class="main-input" value=""/>
<input type="button" class="Create" value="Submit">

和 Jquery 代码:

$('.main-input').on('keyup', function () {
values = $(this).val();
newValue = values.substring();
});
$('.Create').click(function () {
if (values.length === 11) {
alert("yes");
} else {
alert("no");
};
});

PS:可以编辑我的 fiddle 吗?

谢谢。

最佳答案

if (values.indexOf("011") != 0)
alert("invalid!");

关于jquery - 获取输入文本字段的值并将其子字符串化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17538558/

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