Client-Side Validation of asp:TextBox with Javascript

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!
 
V

Vidar Petursson

Hi

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

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
 
M

Matthew Wieder

OK, you win points for the fast valid reply to part one of my problem -
anybody know why the form wont submit?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top