Javascript验证不使用正则表达式

时间:2016-06-17 05:06:59

标签: javascript regex forms

我的javascript验证程序无效。当我什么也没输入时,不显示警报。另外,你们能告诉我关于表格的行动方法是什么以及我应该如何使用它?

;WITH cteTransformTable1 AS (
    SELECT
        'A' as Col1
       ,[A] AS Col2
    FROM
       Table1

    UNION ALL

    SELECT
        'B' as Col1
       ,[B] AS Col2
    FROM
       Table1

    UNION ALL

    SELECT
        'C' as Col1
       ,[C] AS Col2
    FROM
       Table1
)

SELECT *
FROM
    cteTransformTable1 t1
    INNER JOIN Table2 t2
    ON t1.Col1 = t2.Col2
    AND t1.Col2 = t2.Col2

2 个答案:

答案 0 :(得分:0)

您有多个具有相同ID的输入,此处的语法错误不正确

my_form.addEventListener("submit", function(event) {
    // bunch of code...
}. false); // <-- not dot, but comma

检查以下解决方案

&#13;
&#13;
document.getElementById("my_form").onsubmit = function(event) {
  var tomatch = /[a-f]/i;

  //var name = document.getElementById("name").value;
  // you can also get value like this
  var name = document.forms.my_form.name.value

  if (!tomatch.test(name)) {
    event.preventDefault();
    window.alert("The name can only contain letters from a-f");
  }
}
&#13;
<form method="post" id="my_form" method="post" action"/my-url">
  <input type="text" font-size="15px" id="name">
  <input type="submit" id="submit" value="submit" name="submit">
</form>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

使用正则表达式

var tomatch = new RegExp("/[a-f]/i");

问候。