If you want want to go with all HTML5 look at this fiddle: http://jsfiddle.net/bud68oho/2/
This fiddle uses the required
and pattern
attributes to validate the form. The required
attribute does not allow the form to post if the input is not filled in. The pattern
attribute allows you to implement regex for matching. If the input does not meet the requirements of the regex then the form will not post.
The only gotcha with this approach is browser compatibility. Make sure to test this method with your target browsers. The above example works in the latest version of IE and Chrome, I am unable to do any further testing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…