需要帮助验证欧罗巴银行票据无法使其正确验证,不确定原因

时间:2014-11-27 18:41:15

标签: javascript html validation currency

我对新欧罗巴钞票的验证(见下文)不起作用。这是规则:

  

首先需要获取音符的长度,然后转换前两个音符   字母成数字,最后将剩余的数字加在一起。   如果mod by 9返回0,则返回true。

如果有人能帮助我,那就太好了。感谢。

function formValidationCheck() {

  var europaValue = document.form.eurbank.value; //takes value entered
  var europaVal1 = europaValue.charCodeAt(0); // get's the first letter
  var letter1 = europaVal1 - 65;
  var europaVal2 = europaValue.charCodeAt(1);
  var letter2 = europaVal2 - 65;
  var numbers = euuropaValue.substring(3, 12);
  var total = letter1 + letter2 + numbers; // adds total of both letters and numbers
  var tcheck = total % 9; // mods total by 9


  if (europaValue.length > 12) // checks length
 {
    document.getElementById('eurbank').style.background = 'pink';
    document.getElementById('eurbank').style.border = "solid red 2px";
    alert("Bank note number must be less than twleve charaters!");
    return false;
  }


  if (tcheck != 0) //checks the total
 {
    document.getElementById('eurbank').style.background = 'pink';
    document.getElementById('eurbank').style.border = "solid red 2px";
    alert("That is an invalid europa bank note.");
    return false;
  }

}
<form name="form" onsubmit="formValidationCheck();" method="get">
  Full name:
  <br>
  <input type="text" name="fullname">
  <br>Phone number:
  <br>
  <input type="text" name="phonenumber" id="phoneNum" required>
  <br>Email:
  <br>
  <input type="email" name="email" required>
  <br>Credit Card Type:
  <br>
  <select name="credit card type">
    <option value="visa">Visa</option>
    <option value="master">Mastercard</option>
  </select>
  <br>Credit Card Number:
  <br>
  <input type='text' name='creditnum' id='creditnum' required>
  <br>Europa Banknote number:
  <br>
  <input type="text" name='eurbank' id='eurbank' required>
  <br>
  <input type="submit" value="Purchase Now" />
</form>
</div>

1 个答案:

答案 0 :(得分:0)

在进行数值运算之前,请尝试将字母解析为整数。

var total = parseInt(letter1) + parseInt(letter2) + numbers;