Client-Side Validation of asp:TextBox with Javascript

  • Thread starter Thread starter Matthew Wieder
  • Start date Start date
M

Matthew Wieder

Hi - I'm trying to do client-side validation of the text in a Asp.Net
textbox control using javascript. My page has the following:
<form id="Form1" method="post" runat="server" onsubmit="return
validateName(this);">

and

<script language="JavaScript"><!--
function validateName(theForm)
{
var reEval = new RegExp("[\\\/\:\*?\"\<\>|]", "i");

blnEval = reEval.test(theForm.txtName.Value)

if (blnEval)
{
alert("A Valid name must not contain any of the characters
\\/:*?\"<>|");
return false;
}
else
{
return true;
}
}

//--></script>

where txtName is the id in the <asp:TextBox tag. Problem is
1) The theForm.txtName.Value always gives undefined as the value instead
of the actual valus in the textbox.
2) When the Javascript returns true, the page does not submit.

Help anyone?
thanks!
 
Hi

A quick glance
theForm.txtName.value <---- value not Value

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
 
OK, you win points for the fast valid reply to part one of my problem -
anybody know why the form wont submit?
 
Back
Top