小编Jak*_*ake的帖子

如何在javascript中验证电子邮件字段?

这是我用于表单验证的脚本:

<script language="JavaScript">

function formCheck(formobj){
    var fieldRequired = Array("Name", "Email", "Phone", "comments");
    var fieldDescription = Array("Name", "Email", "Phone", "Comments");
    var alertMsg = "Please complete the following fields:\n";

    var l_Msg = alertMsg.length;

    for (var i = 0; i < fieldRequired.length; i++){
        var obj = formobj.elements[fieldRequired[i]];
        if (obj){
            switch(obj.type){
            case "select-one":
                if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            case "select-multiple":
                if (obj.selectedIndex == -1){
                    alertMsg += " - " + …
Run Code Online (Sandbox Code Playgroud)

javascript validation

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

javascript ×1

validation ×1