We ‘ll here add some validation rules to login and register forms from previous post.First lets list out the rules we want.
Validation rules for signup form:
We have three fields in our form – email, username and password, validation rules for them are
- email valid, unique and its a required field
- username unique, contains only alpha numeric characters, minimum of 4 characters and its a required field
- password minimum of 6 characters, it should match the conform password field and its a required field
these rules are defined as,
Validation rules for signin form:
Actually we does’t need any rules for login form, as it only checks the credentials from database and returns an error if the credentials are not found, that’s enough rather than showing errors like username should be 6 characters , alpha numeric…. However if we want rules, we can define some rules like the signup rules above.
In this application, we don’t even need ‘required’ rule as we used html required attribute in our form.
If the validation fails, we ‘ll redirect to the same form with errors,
Then it will return to form, there we can display the errors the way we want,
Now when we fill our signup form with errors, it shows the errors – see the screen shots below,