Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  51] [ 4]  / answers: 1 / hits: 7128  / 10 Years ago, thu, july 24, 2014, 12:00:00

I'm doing a email validation; in the email field, user may put empty space.



So I've decide to $trim the input value and re-assign to input field.



It works normally without any issue, but when I use the space bar couple of time and focus out from the input and turn back, the entered space there in the input field.



Event though I am trimming each of the input - I don't know why the space being with input field.



Any correct approach please?



here is my try:



$('#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


Live Demo


More From » jquery

 Answers
10

hey i gone through your example..



i have changed the binding in it and it is working as expected...



$('#email').on('keyup  change',function(){

var text = $.trim($(this).val() )
this.value=;
this.value=text;

validateEmail.init(this.value);
if(validateEmail.done()){
console.log('this is correct');
}
});


working example:-http://jsfiddle.net/SG6YN/10/



now if user will try to paste text with space then it will remove those spaces..



thanks


[#43640] Wednesday, July 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micayla

Total Points: 148
Total Questions: 92
Total Answers: 109

Location: Aruba
Member since Sat, Oct 2, 2021
3 Years ago
micayla questions
Fri, Dec 24, 21, 00:00, 2 Years ago
Thu, Apr 16, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
;