How the validation to textbox using dropdown select in mvc ?

Posted by Kasani007 under ASP.NET MVC on 8/17/2017 | Points: 10 | Views : 476 | 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.




Responses

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

Up
1
Down
As this is ASP.net 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 Asp.net Forum https://forums.asp.net/t/1441690.aspx?Dynamically+validating+textbox+based+on+dropdown+selected+value , 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 https://stackoverflow.com/questions/30880664/validate-same-textbox-based-on-dropdown-value



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

Login to post response