Regular expression for validating web site url

The [Metadata Type] attribute accepts the type of the class that is supplying metadata information to the User Profile class (User Profile Metadata in this case).

Now, add a new controller in the Controllers folder and name it Home Controller.

regular expression for validating web site url-75

The User Profile Metadata class contains property definitions for First Name, Last Name, Email, Bio, Age, Blog Url and Phone.

Notice the attributes that are used to decorate these properties.

If you don't specify any Error Message, a default error message is displayed.

The [Email Address] attribute validates a property for a valid email address.

NET Entity Data Model to the project so that you get the User Profile entity class as shown above.

In this example, you will validate all of the columns except Id, using various data annotation attributes. NET class (POCO) then you can directly decorate its properties with data annotation attributes.

The [Url] attribute checks whether a property value is a valid URL.

Finally, the [Regular Expression] attribute checks whether a property value matches a pattern as specified by a regular expression.

In this example you validate the Phone property with a regular expression for US phone numbers.

Tags: , ,