Form validation

2019-09-09 15:53发布

问题:

Anyone who can help with uni assignment. I can't make my form to validate. I need to validate only two fields. Email and credit card number. But I suck in javascript. I was trying to make work simultaneously work two scripts. But I didn't succeed. Anyone who can help me? Any links? Maybe some of you know some good and working script? Thank you in advance. Really simple form, only for uni purposes. Form looks like this:

<form name="checkoutform1" action="" method="post">
<table>
<tr>
<td>Email:</td>
<td><input type="text" name="email" size="15" maxlenght="65" value=""/></td>
<tr>
<td>Card number:</td>
<td><input type="text" name="cardnumber" size="16" maxlenght="16" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Purchase"/></td>
</tr>
</table>
</form>

回答1:

Javascript or JQuery is not in a position to validate a form. That is up to the server.

Javascript can only improve the users experience by having a very good stab at sending reasonable data to the server. It is still up to the server to accept/reject it.

Indeed the user is free to disable Javascript.



回答2:

Check out the jQuery Validation plugin. It has credit card and email validation, so you don't need to re-invent the wheel when it comes to basic validation.