Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since Asp.Net is designed according to MVC pattern, There are 3 points of interest to consider.</p> <ol> <li>you may want to limit it only in the UI. (or view)</li> <li>you may want to limit it in the code-behind. (or controller)</li> <li>you may want to limit it in the business logic which process the data (model more or less)</li> </ol> <p>(1)<br/> For UI / View You can use Field Validator to accomplish that. The one that you need is the Regex field validator. And you can read regarding of how to use it here:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ff650303.aspx" rel="nofollow">How To: Use Regular Expressions to Constrain Input in ASP.NET</a></p> <p>(2)<br/> So while this solution will solve the problem in the UI side.. You might want to make sure that your server side controller also limits this. To do that you can set in the ASPX code-behind a call to textbox1.Trim() or use regex commands.</p> <p>(3)<br/> Next, your business logic.. if you created POCO's you might want to put a verifying code in the property which receives the input, or if you prefer your POCO's versatile you can go to your business logic method and make the check in there just before you about to process the information from the input.</p> <p>If I were you I would implement the field validator and do a 2nd check in the API method that is about to process the information, I would rather not alter the ASPX code behind or the model props.<br/> But this is of course more of a matter of style or opinion.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload