Re: Input validation

Efran Cobisi <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.web
Organization cobisi.com
Message-ID <[email protected]>
Hi Gabriel,

Basically there are two ways you could follow. Assuming you have to
validate a string which should be a representation of a double:

a) Use a CompareValidator [1], setting the Operator property [2] value
as DataTypeCheck and the Type property value as Double. This solution
involves writing not a line of code... The only drawback is it would be
not so easy to deal with globalization issues: in fact, this control
would parse the target string with the culture information of the
current thread (or with a neutral culture, if the control is properly
instructed to do so).
b) Implement your own CustomValidator [3] and attempt to parse the
validation property of the target control via, for example,
System.Double.TryParse(). Naturally this one gives you the greatest
control over the validation logic; since you have to implement this
logic, you can, for example, parse the target string with a given
culture information, thus overcoming the limitations of the former.

[1] http://msdn2.microsoft.com/en-us/library/db330ayw(VS.71).aspx
[2]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.validationcompareoperator.aspx
[3]
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx

Hope this helps.

--
Efran Cobisi
http://www.cobisi.com

Gabriel wrote:
>> Go to ajax.asp.net, scroll down the page and click on "watch more
>> asp.net ajax videos" and watch #13 (How Do I: Use the ASP.NET AJAX
>> Client Library Controls), use regexp to check for a valid number
> and without Ajax ?
>
> Thanks,

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.