简体   繁体   English

注册页面验证

[英]Signup page validation

I want to create simplest validation for my signup form.我想为我的注册表单创建最简单的验证。 My signup form contains input fields with default values.我的注册表单包含具有默认值的输入字段。 It must check for values of the fields.它必须检查字段的值。 If user doesn't change default value of the field the script must alert about it.如果用户不更改字段的默认值,脚本必须提醒它。 How can i do it?我该怎么做? my signup form looks like that http://pastie.org/2369498 and reg.js http://pastie.org/2369500我的注册表单看起来像http://pastie.org/2369498和 reg.js http://pastie.org/2369500

You've tagged your question with jQuery, so I'll give you a jQuery answer.你已经用 jQuery 标记了你的问题,所以我会给你一个 jQuery 答案。 You can get the value of a field using the val method:您可以使用val方法获取字段的值:

$("#someField").val();

You can then compare the current value of the field with your default value, and perform some action if that's the case:然后,您可以将该字段的当前值与您的默认值进行比较,并在这种情况下执行一些操作:

if($("#someField").val() === "Default") {
    $("#errorMessage").text("You must enter someField.");
}

You could also look into the jQuery validation plugin .您还可以查看 jQuery验证插件

Update (based on comments)更新(基于评论)

You can get the value of the selected radio button the same way as shown above, with the val method:您可以使用val方法以与上所示相同的方式获取所选单选按钮的值:

var selectedType = $("input[name=type]").val();
switch(selectedType) {
    case "1":
        //Validate required fields as shown above
        break;
    case "2":
        //Validate next lot of fields
        break;
    //Continue with as many sections as you have.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM