验证电子邮件客户端

时间:2012-12-27 21:06:21

标签: javascript email-validation

  

可能重复:
  Validate email address in Javascript?

当服务器端无法验证时,如何使用javascript在客户端验证电子邮件?从我的理解Javascript可以关闭,所以如何实现这一点,并阻止我接收PCI警告?

$(document).ready(function() {

var clearMePrevious = "";

// clear input on focus
$("#email").focus(function() { 
    if($(this).val()==$(this).attr("title")) {
        clearMePrevious = $(this).val();
        $(this).val("");
    }
});

// if field is empty afterward, add text again
$("#email").blur(function() {
    if($(this).val()=="") {
        $(this).val(clearMePrevious);
    }
});

$('#submitemail').click(function() {
    app.ajax.load({
         reqName : 'emailSubmit',
         url: '$httpUrl('Bronto-OptIn')$?email=' + $('#email').val(),
         selector : '#emailbox',
         callback: function(responseText, textStatus) { }
    });
            return false;
});

});

<form id="emailsignup_form" name="emailsignup_form" method="post" action="$httpUrl('Bronto-OptIn', 'fid', 'information')$">
<div class="fl"><input class="email-signup-input" type="text" title="Enter Your Email Address" value="Enter Your Email Address" name="email" id="email" /></div>
<div class="fl"><button class="email-signup-btn" value="Submit" name="submitemail" id="submitemail">Submit</button></div>
<div class="clear">&nbsp;</div>

1 个答案:

答案 0 :(得分:0)

如果客户端验证是必要的,我会在没有启用javascript的情况下进行回退 -

<script type="javascript">
    /* Wire up form submittal */
</script>
<noscript>
    <p>JavaScript is required to use this form, please enable JavaScript in your browser!</p>
</noscript>

看到这个 - How to detect if JavaScript is disabled?