Total Page Preview:   000000005516

What is custom validator in ASP.NET in English and Hindi

 

Custom validator in ASP.NET in English

Custom Validator is an ASP.NET validation control that allows you to write your own validation logic for an input control. It provides a way to validate user input using custom validation logic that cannot be accomplished using the built-in validation controls.
Here's an example of how to use the CustomValidator control to validate that the value entered in a TextBox control is a valid email address:
 
 
In this example, the CustomValidator control is used to validate the email address entered in the Email TextBox control. The ControlToValidate property specifies the ID of the control to validate. The Validate Empty Text property is set to true to ensure that the validator fires even if the control is empty. The ErrorMessage property specifies the error message to display if the validation fails.
The OnServerValidate event handler is used to specify the custom validation logic. Here's an example implementation of the ValidateEmail event handler:
 
 
In this example, the ValidateEmail event handler uses a regular expression pattern to validate the email address entered in the EmailTextBox control. If the email address matches the pattern, the event handler sets the IsValid property of the ServerValidateEventArgs object to true to indicate that the validation succeeded. If the email address does not match the pattern, the event handler sets the IsValid property to false to indicate that the validation failed.
When the user submits the form, the CustomValidator control will fire the ValidateEmail event handler to validate the email address entered in the EmailTextBox control. If the validation fails, the error message specified in the ErrorMessage property will be displayed.
 

Custom validator in ASP.NET in Hindi

CustomValidator ek ASP.NET validation control hai jo aapke dwara likhe gaye apne khud ke validation logic ko input control ke liye use karne ki anumati deta hai. Ye user input ko validate karne ka ek tarika pradan karta hai jo ki built-in validation controls ka istemal karke nahi kiya ja sakta hai.

Yahan ek CustomValidator control ka istemal karte huye bataya gaya hai jo verify karega ki TextBox control mein enter kiya gaya value ek valid email address hai ya nahi:

 
Is example mein, CustomValidator control EmailTextBox control mein enter ki gayi email address ko validate karne ke liye istemal kiya jata hai. ControlToValidate property mein validate kiye jane wale control ka ID specify kiya jata hai. ValidateEmptyText property ko true set kiya jata hai taki validator khali control ko bhi validate kar sake. ErrorMessage property mein validation fail hone par display hone wala error message specify kiya jata hai.
OnServerValidate event handler ko use karke custom validation logic specify kiya jata hai. Yahan ValidateEmail event handler ka ek example diya gaya hai:
 
 
Is example mein, ValidateEmail event handler ek regular expression pattern ka istemal karke EmailTextBox control mein enter kiye gaye email address ko validate karta hai. Agar email address pattern se match karta hai to event handler IsValid property ko true set karta hai jisse validation pass ho jati hai. Agar email address pattern se match nahi karta hai to IsValid property ko false set karta hai jisse validation fail ho jati hai.
Jab user form submit karta hai to CustomValidator control ValidateEmail event handler ko call karta hai jisse EmailTextBox control mein enter ki gayi email address validate hoti hai. Agar validation fail hoti hai to ErrorMessage property mein specify kiya gaya error message display hota hai.
 
 
 
 
 
 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments


                           
                           

                           

                           

Facebook User: