I'm current working on jquery and have a problem about the validation usage. I made a code for register but when i run it, nothing happened and there's no error show up, either. can anyone help me with that?
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" ></script>
<script type="text/javascript" scr="js/signup-form.js"></script>
<script>
$().ready(function () {
$("#registerForm").validate({
rules: {
email: {
required: true,
email: true
},
userName: {
required: true,
minLength: 8
},
password: {
required: true,
minlength: 8
},
passwordConfirmation: {
required: true,
equalTo: "#password"
}
},
messages: {
email: {
required: "This field can not be empty",
email: "Email address does not valid"
},
userName: {
required: "This field can not be empty",
minLength: "UserName must contain at least 8 charactors"
},
password: {
required: "This field can not be empty",
minLength: "Password must contain at least 8 charactors"
},
passwordConfirmation: {
required: "This field can not be empty",
equalTo: "Please enter the same password above"
}
}
});
});
</script>
<form id="registerForm">
<fieldset>
<div>
<p>
<label>Email</label>
<input type="email" value="@Model.Email" name="email" id="email" />
</p>
<p>
<label>Username</label>
<input tyep="text" value="@Model.UserName" name="username"/>
</p>
<p>
<label>Password</label>
<input type="password" value="@Model.Password" name="password"/>
</p>
<p>
<label>Confirm Password</label>
<input type="password" value="@Model.PasswordConfirmation" name="passwordConfirmation" />
</p>
</div>
</fieldset>
<p>
<input type="submit" vaule="Register" />
</p>
</form>
when i hit the register button, nothing happened and there's no error. can anyone help me out with that?
by the way, i using visual studio MVC 5, does that make any problem?
thanks!!!
@edit:
i have tried my code at hjsfiddle.net/5d1b50k6 and it works fine. but it still not working in my computer. does mvc would affect that??
$().ready(...)should be$(document).ready(...); and you've misspelledminlengthasminLength.unobtrusive-validationplugin? If so, that would be taking precedence over your.validate()method.