Description
Your html page will includethree textboxes for username, password and phone number, one “Validate” button and one empty paragraph at the end of the page. Whenuser clicks on the button, you will validate the user input by using Javascript.
Validation rules: co
- All fields are mandatory.
- Username and password should be at least 6 characters.
- Phone number should include only numbers.
If user input is valid, change the text for paragraphand show the success message.The text color for the success message will be green.
If it is not valid, change the text for the paragraph andshow all errors. The text color for the error messages will be red.
Write unobtrusive script code for attaching event handlers to the events and also for changing style properties of elements (css properties should be defined as css classes and you should change the class of the paragraph from Javascript).
Note: Check rules 2 and 3 only if all fields are given. Otherwise show error message “All fields are mandatory”.
- Do not use “required” attribute on HTML
- Change the CSS class in JS and not CSS property(eg: color)
- Use click event handler in JS
- *Try to use regular expressions for validation
改进:
在validate最开始reset一下颜色
整合一下变颜色的,写成一个函数
变成onclick()