我正在进行电子邮件验证;在电子邮件字段中,用户可能会输入空格。
因此,我决定使用
它正常工作没有任何问题,但当我使用空格键几次并从输入框中移出焦点然后再回来时,输入的空格还在输入框中。
尽管我每个
请问有正确的方法吗?
这是我的尝试:
因此,我决定使用
$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