2012-12-27 133 views
0

可能重複:
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> 

+2

爲什麼能」服務器驗證?無論你做什麼,客戶端驗證都是不安全的。 – elclanrs

+1

不完全瞭解你的問題。您可以使用正則表達式驗證客戶端(類似於** ^。+ @。+(\ .. +)+ $ **)。但是,如果用戶禁用JavaScript,您總是希望再次在服務器上驗證輸入。這個問題與PCI有什麼關係? – Sam

+1

客戶端驗證通常只是給用戶提供快速反饋,並且所有的驗證都必須在服務器上重做,因爲服務器必須保持其數據庫不會收到不良內容,並保護自己免受惡意輸入。 –

回答

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?