| | |
JavaScript Validation on Textbox
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
Hi
I use Visual 08 ASP.NET C# and JavaScript
I would like to do the following validation on a text box
the length MUST be 12 characters long in the following format
LLLLLLNNNNNN
Where
L = Letters
N = Numbers
if the users input does not match the required format i want the textbox's backcolor to go red , but if the users input matches the required format i want the textbox's text to go green.
I have absolutely no idea how to do this in Javascript so any help would be appreciated.
Thanks in advance.
Regards.
I use Visual 08 ASP.NET C# and JavaScript
I would like to do the following validation on a text box
the length MUST be 12 characters long in the following format
LLLLLLNNNNNN
Where
L = Letters
N = Numbers
if the users input does not match the required format i want the textbox's backcolor to go red , but if the users input matches the required format i want the textbox's text to go green.
I have absolutely no idea how to do this in Javascript so any help would be appreciated.
Thanks in advance.
Regards.
Last edited by cVz; Oct 8th, 2009 at 5:02 am.
Delphi & C# programmer deluxe...
0
#2 Oct 8th, 2009
I have a solution for the first problem for you . ie., checking out if length is 12 characters long.
Say if u have a txt box labeled "txtuserid" and a label to display error "lblError"
u can use the following function in java script to check the length and display error if the length is less than 12.
for the next requirement of yours ie., for checking if it is 6 letters followed by 6 numbers, i suggest that u can use the regular expression validator control and get the text box validated.
cheers,
saradha
Say if u have a txt box labeled "txtuserid" and a label to display error "lblError"
u can use the following function in java script to check the length and display error if the length is less than 12.
ASP.NET Syntax (Toggle Plain Text)
<head> <script language="javascript" type="text/javascript"> function validateElements() { var username=document.getElementById('txtuserid').value; if(username.length<12) { document.getElementById('lblError').innerText="Userid Less than 12 characters"; return false; } } </script> </head>
for the next requirement of yours ie., for checking if it is 6 letters followed by 6 numbers, i suggest that u can use the regular expression validator control and get the text box validated.
cheers,
saradha
•
•
Join Date: Jul 2008
Posts: 40
Reputation:
Solved Threads: 6
0
#4 Oct 13th, 2009
Check if this helps:
ASP.NET Syntax (Toggle Plain Text)
JS: <script type="text/javascript" language="javascript"> function validate(sender,args) { args.IsValid = false; var tb = document.getElementById('txtInput'); if (args.Value.match(/^\w{6}\d{6}$/)) { args.IsValid = true tb.style.backgroundColor = "white"; tb.style.color="green"; } else { tb.style.backgroundColor = "red"; } } </script> Markup: <asp:TextBox ID="txtInput" runat="server"></asp:TextBox> <asp:Button ID="btnSubmit" runat="server" Text="Button" /> <asp:CustomValidator ID="CustomValidator1" ControlToValidate="txtInput" runat="server" ErrorMessage="*" ClientValidationFunction="validate"> </asp:CustomValidator>
![]() |
Similar Threads
- javascript validation code without alert box (JavaScript / DHTML / AJAX)
- Javascript Validation (JavaScript / DHTML / AJAX)
- Really Stuck - ASP/Javascript Form Validation (ASP)
- Javascript - Validation (JavaScript / DHTML / AJAX)
- Javascript Input Mask / Validation (JavaScript / DHTML / AJAX)
- javascript validation (JavaScript / DHTML / AJAX)
- Javascript, Form fields validation and submit (JavaScript / DHTML / AJAX)
Other Threads in the ASP.NET Forum
- Previous Thread: Microsoft Server & What Programming IDE for developing ASP.Net Sites can I install?
- Next Thread: Summary validation problem
| Thread Tools | Search this Thread |
.net 2.0 access activedirectory ajax ajaxcode ajaxhelp array asp asp.net aspconnection automatically box c# c++ cart class combobox connection console database databaseconnection datagrid datalist datetime developer development dom dropdownmenu editor email enabled excel file firefox flash focus form getselection gwt html http httpwebrequest iframe index input internet intranet java javascript jquery jsf jsp label list listbox math microsoft msdn mysql news office panel path photoshop php pointer post print programming read regex remote remoting richtextbox robot runtime save scale search security shopping software sql sql-server sqlserver string table tables text textbox tracking treeview usercontrol validation vista visual visualstudio winforms wpf






