For instance you may check that an email address has the '@' in it and say a certain prefix of yahoo, hotmail, google, netmail or any other web based email providers.
So for instance if you wanted to check if an email had the '@' symbol in it then in a validation event for the email field you would say:
If InStr(txtEmail.Text, "@") = 0 Then
MsgBox("The email must include the '@' symbol. " )
End if
The InStr operator checks 'In the String' for the value and the parameters you put in brackets are the (txtemail.text) field, and then what you want to find in the string i.e. the '@' symbol.
If the '@' value wasn't present then you would want to return the focus to the field until the value does include a '@' symbol. Within the code you would set the focus to the field if the check failed. This would return the user to that field until the check passed. If you did not do this then the user could move on and leave an unvalid value in the field. So the code would look like this:
If InStr(txtEmail.Text, "@") = 0 Then
MsgBox("The email must include the '@' symbol. " )
txtEmail.Focus()
End if
InStr returns a numeric value so if the value is 0 then this means the '@' symbol wasn't found.
You can do any checks at validation, this example is only one type of check.
No comments:
Post a Comment