If a form is long or complex, reporting errors only after the page is submitted can be inconvenient to the user.You can add support to perform validation in client script.The reason your current code doesn't work is because you don't have a FORM tag in there.Also, lookup using "name" is not recommended as its deprecated.When you restrict the values that users can enter in forms, you reduce the chance that someone can enter a value that can compromise the security of your site.To see how validation works, run this page and deliberately make mistakes.For example, here's what the page looks like if you forget to enter a course name, if you enter an, and if you enter an invalid date: By default, user input is validated after users submit the page — that is, the validation is performed in server code.A disadvantage of this approach is that users don't know that they've made an error until after they submit the page.
A typical example is a page where a value is passed in a query string, as in the following example: source, including form-field values, query-string values, and cookie values.
If a user enters a non-integer value, the error is reported as soon as the user leaves the entry field.
Users get immediate feedback, which is convenient for them.
However, the test will be performed in server code.
You can control how validation errors are displayed by defining CSS classes that have the following reserved names: .
Search for input validating:
For example, if a page has an element as a placeholder for an individual field error, even if there is no error.