stephenk1973
Technical User
I have tried to create my first custom validation on a text box using funciton on the net. The text box is to be passed to a stored procedure.
Validation always returns false, i'm not sure if the funciton is being called at all. Validation occurs when you press 'enter', and it always seem to pass the variable to the procedure regradless.
Any other validation ( required, range etc) all work fine, where am i going astray or is there a good 101 on custom validation.
Thanks
Stephen
Function IsValidField(ByVal stext)
{
var ValidChars = "0123456789, ";
var IsGood=true;
var Char;
alert(document.Form1.textbox1.Value);
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsGood = false;
}
}
return IsGood;
}
<asp:TextBox ID="TextBox1"
runat="server">
</asp:TextBox>
<asp:CustomValidator
ID="CustomValidator1"
runat="server"
ControlToValidate="TextBox1"
ErrorMessage="CustomValidator"
ClientValidationFunction="IsValidField">*
</asp:CustomValidator>
Validation always returns false, i'm not sure if the funciton is being called at all. Validation occurs when you press 'enter', and it always seem to pass the variable to the procedure regradless.
Any other validation ( required, range etc) all work fine, where am i going astray or is there a good 101 on custom validation.
Thanks
Stephen
Function IsValidField(ByVal stext)
{
var ValidChars = "0123456789, ";
var IsGood=true;
var Char;
alert(document.Form1.textbox1.Value);
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsGood = false;
}
}
return IsGood;
}
<asp:TextBox ID="TextBox1"
runat="server">
</asp:TextBox>
<asp:CustomValidator
ID="CustomValidator1"
runat="server"
ControlToValidate="TextBox1"
ErrorMessage="CustomValidator"
ClientValidationFunction="IsValidField">*
</asp:CustomValidator>