Hi Moondaddy,
Thanks for posting here. Based on your description, you 're looking for
some approachs to validate the input fields(textbox) 's value's length on
ASP.NET web pages. You're wondering whether need to use a certain validator
control or just some clientside script block, yes?
As for this question, I think the clientside script is enougth if you don't
need very complex function. For example, we can get a textbox's value's
length via such script:
textbox.value.l ength
then, we can validate the value as what we want.
And here is an sample on using the javascript to retrieving text field
value's length and do validation on it:
-------------------------------aspx page---------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Validate Length</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language=javasc ript>
function ValidateLength( oid, min, max)
{
var txt = document.getEle mentById(oid);
var length = txt.value.lengt h;
alert("input's length is " + length);
if(length<min || length>max)
{
alert("Invalida ted!");
}
else
{
alert("Validate d!");
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><INPUT id="txtContent " type="text"></td>
<td><INPUT id="btnValidate " type="button" value="Validate "
onclick="Valida teLength('txtCo ntent',4,8)" >(Length must
be limited be tween 4----8)</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</form>
</body>
</HTML>
------------------------------------------------------------------
NO additional code behind code needed
If you need complex functions on validating, you can also implement them
via javascript if you want to implement them at clientside. In addtion, the
ASP.NET's custom validator control also provide the functions which let you
use Regular expressions to customize your own validation rules. Here is the
related document on it:
#Regular Expression Validator Control Sample
http://msdn.microsoft.com/library/en...larexpressionv
alidatorcontrol sample.asp?fram e=true
Please check out the preceding suggestions to see whether they help. If
you have any further questions, please feel free to post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx