Validating user input with javascript

Font size can be set using percentage, pixels, points or ems, etc, etc.You need to work out which one the user has supplied and whether it is valid.

For example, you need to define a list of the properties/attributes that you will allow the user to provide CSS rules for.

Then you need to define the range of acceptable values for each property. red), Hex (short and long form eg #fff or #ffffff) and RGB.

Once you master the pattern language, most validation tasks become trivial.

You can perform complex tasks that once required lengthy procedures with just a few lines of code using regular expressions.

You also need to validate whether the property being styled is appropriate for the element.

And those are just some of the first issues to manage that came off the top of my head. As I said, writing your own CSS validator is not a trivial undertaking.

It’s a tool for performing pattern matches and it has to categories 1 after we have got a regular expression we can use it any where and here’s an example that may be helpful -In this example we insure that the user enters 6 digits.

When users enter data into your application, you may want to verify that the data is valid before your application uses it.

You may require that certain text fields not be zero-length, that a field be formatted as a telephone number or other type of well-formed data, or that a string not contain any unsafe characters that could be used to compromise the security of a database.

Tags: , ,