我正在做一個電子郵件驗證;在電子郵件字段中,用戶可以放置空白空間。如何刪除輸入字段中的空白並重新分配修剪值
所以我決定$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