Universal form verification function

xiaoxiao2021-03-06  106

Universal form verification function

Whether it is a dynamic website, or other B / S structure, it is not inseparable from the form of the form to the server to submit the data to the server to submit a considerable role. This will lead to a problem, is it legal? The problem in front of us is to verify that the data submitted by these data is legal. So, we wrote a big pile of verification functions. When we started the development of a new project, we have to write a lot of verification. Function, then debug this large number of functions ...

This article will introduce a method to improve my credibility and improve our development efficiency.

Personally think that the verification of the form should contain two parts: First, determine whether the data entered by the user is legal. Second, prompting that the user is not legal.

Therefore, our generic form verification function to be implemented is: First, obtain the data GetValue (EL) of the user input, verify the user's data checkform (OFORM) IE supports custom properties, this is this universal function. Based we can add the properties of your own information on the form element. It is a bit like XML .check property: This property is used to store the regular expression of the data legitimacy. Warning property: This property is used to store error prompt information. Third, return incorrect form Tips Goback (EL) The trigger event of these three steps is onSubmit, remember that return checkform (this) is wrong, it is full of fullness:)

Writing here, the overall frame is coming out, obtaining a string to obtain a string, build a regular expression by obtaining the check attribute of the form element, and then verify its value. If the verification is submitted, if the data is not legal, the WARNING attribute of the form element will be obtained. Tip information. Return to the form element. The entire framework is relatively simple. What we have to do is write a good regular expression!

Next, let's analyze all the form elements according to their partnership, we divide them into three types of each type of form, and our goal is to write universal.

1. Wen input box text