我一直试图完成这项工作,但没有成功.我使用正则表达式来验证用户根据通过单选按钮选择的信用卡类型输入的信用卡号.但我记得对所有if语句发出警报.看起来所有if else语句都经过测试.
There is the HTML code fragment:
<code>
<p><b>Payment Information:</b></p>
<fieldset>
<input type="radio" name="payment" value="Visa" id="visa" />Visa
<input type="radio" name="payment" value="Master Card" />Master Card
<input type="radio" name="payment" value="American Express" />American Express
<input type="radio" name="payment" value="Discover" />Discover <br /><br />
<label>Card Number:</label>
<input type="text" name="cardNumber" id="cardNum" size="30" value="" onblur="ValidateCreditCardNumber()" />
</code>
And there is my javascript function :
<code>
function ValidateCreditCardNumber(){
var ccNum = document.getElementById("cardNum").value;
var visaRegEx = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
var mastercardRegEx = /^(?:5[1-5][0-9]{14})$/; …Run Code Online (Sandbox Code Playgroud)