Search code examples
jquerylivevalidation

Jquery Livevalidation email


Today, I faced a problem in live validation. When i enter in email in textbox as [email protected] ie . (space)[email protected] . It throws an error as 'Invalid email'. I want to trim the email and then validate in livevalidation

html

<input type="text" placeholder="Email" maxlength="255" class="element  text medium" name="email" id="email">

js

var f11 = new LiveValidation('email');
var f1 = f11.replace(/\s/g , '');// to remove space in email id
f1.add(Validate.Presence);
f1.add(Validate.Email); 

I want to trim the email field then it can be validate by live validation. Any Ideas


Solution

  • Why don't you attach an "onChange" event to the input field using jQuery and have that clear any spaces in prefix/suffix; as user types?

    html

    <input type="text" placeholder="Email" maxlength="255" class="element  text medium" name="email" id="email">
    

    javascript

    $(document).ready(function() {
        $('#email').change(function() { 
            $(this).val(
                $.trim(
                    $(this).val()
                )
            );
        });
    });