How the validation to textbox using dropdown select in mvc ?

Posted by Kasani007 under ASP.NET MVC on 8/17/2017 | Points: 10 | Views : 2349 | Status : [Member] | Replies : 1
I Have A dropdown having values integer,string etc, when i select dropdown item, the textbox beside dropdown should validate with the selected dropdown item. i.e., if i select integer, then it validates that only integer values should enter in the textbox or if i select string, then it should validate that only string should enter in the textbox.


Posted by: Ajay2707 on: 8/21/2017 [Member] Starter | Points: 25

As this is MVC question, you can do this via 2 approach. You need to use regular expression which validate your text based on your dropdown type.

From Back-end validation (Server side validation)
Create a ajax web-method function which validate your textbox based on your dropdown value.

From Front-end validation (HTML side validation).
For this you should create a Javascript / jquery function which manually enforce your validation as this is not standarad validation requirements, but custom requirement.

please refer this Forum , in this you got both approach idea (I refer idea the reason is the question is related to webform and you need in mvc, so need to change)

1. For first approach refer Scott927's answer
2. For second approach refer imran_ku07's answer.

Also see this Stackoverflow

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response