2

however my question is simple but I don't know it's answer. I use range validators in my project. I know how they work for integer or float or dates but I don't know how they works for strings. for example if the min value is "xx" and the max value is "zzyyyz" ,what the users can enter? can you get me an example?

Angel
  • 733
  • 1
  • 7
  • 12

1 Answers1

0

If you look at the documentation of the RangeValidator, it appears you can specify a string type:

<asp:RangeValidator runat="server"
                    MaximumValue="zz"
                    MinimumValue="xx" 
                    Type="String" 
                    ... />

Although you may be better off using a RegularExpressionValidator. In this example, you'd have:

<asp:RegularExpressionValidator runat="server"
                                ValidationExpression="^[x-z]{2}$"
                                ... />
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
  • but my purpose of this question is that what strings can be entered. xx and zz just are an example. – Angel Jun 30 '13 at 17:57
  • @Angel See the first part of my answer. If you tried it and it's producing the result you expected, please include that as part of your question. – p.s.w.g Jun 30 '13 at 18:21
  • my question is when we determine min string and max string , how it works? in fact what strings are allowable for users? – Angel Jun 30 '13 at 18:29
  • 1
    @Angel I imagine it does something like `string.Compare(input, minimumValue) >= 0 && string.Compare(input, maximumValue) <= 0` – p.s.w.g Jun 30 '13 at 18:34
  • what does it compare? just number of charcters? – Angel Jun 30 '13 at 18:38
  • 1
    @Angel [`string.Compare`](http://msdn.microsoft.com/en-us/library/system.string.compare.aspx) compares each character. I'm not entirely sure that `RangeValidator` uses that technique, but I believe it does. If you have doubts, try it out (I don't have the ability to test it myself at the moment). – p.s.w.g Jun 30 '13 at 18:56
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/32649/discussion-between-angel-and-p-s-w-g) – Angel Jun 30 '13 at 19:01