2013-10-16 53 views
1

今天,我在现场验证所面临的一个问题。当我在电子邮件中的文本框中输入为[email protected]即。 ([email protected])。它会将错误作为“无效的电子邮件”引发。我要修剪的电子邮件,然后在livevalidationjQuery的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); 

我要修剪的电子邮件字段,则可以通过现场验证来验证。任何想法

回答

1

使用jQuery你为什么不附加一个“的onChange”事件输入字段,并有明确的前缀/后缀的任何空间;作为用户类型?

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() 
      ) 
     ); 
    }); 
});