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.length
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>ValidateLength</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
<script language=javascript>
function ValidateLength(oid, min, max)
{
var txt = document.getElementById(oid);
var length = txt.value.length;
alert("input's length is " + length);
if(length<min || length>max)
{
alert("Invalidated!");
}
else
{
alert("Validated!");
}
}
</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="ValidateLength('txtContent',4,8)" >(Length must
be limited between 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-us/cpguide/html/cpconregularexpressionv
alidatorcontrolsample.asp?frame=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