1

I am performing both clientside and serverside validation , clientside-jquery and serverside-asp.net I am using custom validators for checking numeric textboxes.The issue is there are few textboxes that need to check for numeric data and length of the data and also digits after decimal.so i guess i cannot create a common onservervalidate function for all of them as their validation needs differ. So do i need to use different validation controls for all of them ..can i call three different method on one onservervalidate... any suggestions thanks

2
  • Normally you would use one validator for each control to be validated. Commented Mar 2, 2012 at 8:38
  • @TimSchmelter that means if a textbox requires to be numeric , also length of data should be 10 , and also it should have 2 digits after decimal ,,,, then i will require three custom validators for numeric data ,length and decimal ....Is it so ... Commented Mar 2, 2012 at 8:42

2 Answers 2

1

You can use the regex class. Within that you only need one function to validate your data with all your requirements.

the regex class is a powerful class where u can define complex patterns that the string has to match. this is one of my simpler regex validator function for my page which returns a boolean if the string send in the parameter (pass) matches the pattern.

    Public Function validatepass(ByVal pass As String) As Boolean
    Dim pattern As String = "^\S{6}\S*$"
    Dim MatchString As Match = Regex.Match(pass, pattern)
    If MatchString.Success Then
        Return True
     Else
        Return False
     End If
     End Function

it works like this: Dim pattern As String = "^\S{6}\S*$" // in this line u define the pattern, ^ is the left end of the string, and $ is the right end \S{6} is matching the first 6 chars of the string and accepts ANY chars except whitespace chars \S* does nearly the same, but * means that it can be any number of chars ( again any chars except whitespace chars )

so effectivly this pattern does not accept whitespaces and requires the string to be at least 6 chars long

for a comprehensive guide u should read this : http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial

and in ur case the regex pattern should be this : ^\d{10},\d{2}$

u can use the same pattern syntax for serverside validation via a function like this, or clientside by creating a customregex validator and using the pattern in the appropriate property.

Sign up to request clarification or add additional context in comments.

1 Comment

could you just elaborate a bit more , as it would be more helpful
1

The issue is there are few textboxes that need to check for numeric data and length of the data and also digits after decimal.

So you basically have three needs...

  1. Must have some value.
  2. Numeric value
  3. Decimal value

Here is three in one solution..using ReguarExpressionValidation

<asp:RegularExpressionValidator ID="ValExp" runat="server" 
ValidationExpression="^[0-9]+(\.[0-9]+)$" 
ControlToValidate="Controlname"></asp:RegularExpressionValidator>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.