This is a discussion on Validation Function / Class within the .Net Development forums, part of the Programming & Scripting category; Does anyone use a standard class or function to provide validation in their apps? In a previous app I wrote ...
| |||||||
|
#1
| ||||
| ||||
| Does anyone use a standard class or function to provide validation in their apps? In a previous app I wrote a validation function that took parameters of the value to validate, the max length it could be, whether it was required and a code to use a specific regex pattern to validate. So, I could reuse this function on all form controls to validate the content. My preference is to have an "error display box" on the page that is used to display any validation errors on a sequential, singular basis. For example, suppose you had the following page:- Code: <asp:panel id="pnlError" runat="server"> </asp:panel> <asp:textbox id="textbox1" runat="server" /> //This element is required <asp:textbox id="textbox2" runat="server" /> //This element can only accept [a-z] I don't know if this is a particularly good or acceptable method of validating? I know .NET provides validation controls. Does anyone just use these or do you have a standard function that you reuse in apps? What method(s) do you guys tend to use? btw, I know about providing client side and server side validation. I'm referring just to server side here.
__________________ Join the folding team |
|
#2
| ||||
| ||||
| Generally i use different code for validation on each page. If there is some special validation like email, integer, etc...; i make their functions separately and just use them on each page.
__________________ Get the Mantra! |
|
#3
| ||||
| ||||
| Quote:
Could you just do a quick, simple example? |
|
#4
| ||||
| ||||
| Sometimes i use the built in ones like IsDate, like Code: If strDate = String.Empty Or Not IsDate(strDate) Then
sText = " Date!"
End If
Code: If Regex.IsMatch(strLongitude, CGlobal.CheckFloat) = False Then
sText = " Longitude is in Wrong Format!"
End If
Code: Public Shared Function CheckFloat() As String
'Decimals value
CheckFloat = "^(-)?[0-9]+(\.[0-9]{1,10})?$"
End Function
|
| The Following User Says Thank You to micky For This Useful Post: | ||
richyrich (November 16th, 2009) | ||
|
#5
| ||||
| ||||
| I only use the validation controls. I have a lot of fun with the RegularExpressionValidator.
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.If you like it here...throw us a few bones to help support us. Join our Folding team: DeveloperBarn Folding |
|
#6
| ||||
| ||||
| Quote:
Also, what about if you have a required field and one that should only contain [a-z], for example? |
|
#7
| ||||
| ||||
| Code: <asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"
Display="Dynamic"
ErrorMessage="TextBox1 is required"
Text="*" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1"
Display="Dynamic"
ErrorMessage="TextBox1 contains invalid characters"
Text="*"
ValidationExpression="^[a-zA-Z]$" />
|
| The Following User Says Thank You to jmurrayhead For This Useful Post: | ||
richyrich (November 16th, 2009) | ||
|
#8
| ||||
| ||||
| But you would still need server side validation...... right?? |
|
#10
| ||||
| ||||
| Nice. So then server side validation can be by-passed!! Lot of code would have been saved by me |
![]() |
|
| Bookmarks |
| Tags |
| controls, function, validation |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Email Class | jmurrayhead | .Net Code Samples | 2 | July 8th, 2009 07:49 AM |
| Button Class | richyrich | HTML & CSS Help | 18 | February 27th, 2009 12:32 PM |
| class name is ambiguous | richyrich | .Net Development | 11 | August 12th, 2008 11:11 AM |
| FTP Class Library? | Wolffy | .Net Development | 6 | May 30th, 2008 10:26 AM |
| Class library | Shem | .Net Development | 11 | May 22nd, 2008 07:01 AM |