我正在做一个电子邮件验证;在电子邮件字段中,用户可以放置空白空间。如何删除输入字段中的空白并重新分配修剪值
所以我决定$trim
的输入值,并重新分配给输入字段。
它的工作原理没有任何问题,但是当我使用空格键几次并从输入焦点出来并返回时,在输入字段中输入空间。
事件虽然我正在修整每个input
- 我不知道为什么空间与input
字段。
请问有没有正确的方法?
这里是我的尝试:
$('#email').on('input change',function(){
this.value = $.trim(this.value); //re-assigning trimmed value, but not works when enterning space and focus out. when focus in the space being in the input
validateEmail.init(this.value);
if(validateEmail.done()){
console.log('this is correct');
}
});
//enter some space and focus out, then come back to input field you can see white spaces in the field
你真的需要在输入框中删除每一个空间?你为什么不把它传递给你的电子邮件验证时修剪它? ('validateEmail.init($。trim(this.value));') – Padarom
在FF中正常工作,但不在铬 – imbondbaby
我想避免空白基本上,因为这是电子邮件地址。再次用户可以复制粘贴一些不需要的白色空间..它在输入字段变得非常冗长。 – 3gwebtrain