473,413 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

validate text box

how to validate a text box compare with the values stored in an array. the text box is for username.
Aug 14 '12 #1
2 1962
gits
5,390 Expert Mod 4TB
what do you have done so far? please post your code. Basicly you need to decide when the validation should be executed - so find an event where you register the validation handler and where you then implement the validation logic.
Aug 14 '12 #2
ariful alam
185 100+
Try the below code.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>check array contains</title>
  4. <script language="JavaScript">
  5.  
  6. var ids=new Array("name1","name2","name3");
  7.  
  8. function validate(userid)
  9. {
  10.     if(userid=="") {
  11.         alert('user id is not given.');
  12.     }
  13.     else if(contains(ids,userid)) {
  14.         document.getElementById('msg').innerHTML="<b>"+userid+"</b> found.";
  15.     }else{
  16.          document.getElementById('msg').innerHTML="<b>"+userid+"</b> not found.";
  17.     }
  18. }
  19.  
  20. // contains function
  21. function contains(arr, findValue) {
  22.     var i = arr.length;
  23.  
  24.     while (i--) {
  25.         if (arr[i] === findValue) return true;
  26.     }
  27.     return false;
  28. }
  29.  
  30. </script>
  31. </head>
  32.  
  33. <body>
  34.  
  35. <div id='msg'></div>
  36. <label>User ID: <input type='text' size='30' id='userid' name='userid' placeholder='please enter your id'/></label>
  37. <input type='submit' name='login' value='check' onclick="javascript:validate(document.getElementById('userid').value);"/>
  38.  
  39. </body>
  40. </HTML>
hope it's help you. :)
Aug 14 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mike | last post by:
I'm using a script provided by e-mailanywhere, it's a little too big for me. There's 1 text field and 1 password field in a form. OnSubmit, I would like both fields to be validated to look for...
7
by: ms_chika | last post by:
hi to all! I just want to ask if how could i validate a text or string if it has a space between characters? Thanks in advance. *** Sent via Developersdex http://www.developersdex.com ***...
7
by: Dragon | last post by:
Hi, I am trying to find out if there is a good (Built-in?) way to validate text input. I would like to check a textbox to see whether user enter a proper name (without numbers, symbols etc) or...
1
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
I have a text box. It's input should be integer. I want to validate this text box so that it's value should be integer. What validation control shouuld I use. Thanks
1
by: kickergirl | last post by:
I'm not sure my title actually describes my problem, but here it goes. I am creating a form to track account information for participants. Basically, a single participant can be offered up to...
4
by: Angela | last post by:
Hello How would one auto validate using the 'onchange' method a text box for invalid entries? Invalid entries would include: 1. Input string of '....' 2. Input string of 'aaaa' 2. Check...
6
by: neehakale | last post by:
M doing an application where i need to validate a text box contaning name for only alphanumric characters. M using windows forms in c#..can anybody tell me the methos to do this???
2
by: mmv | last post by:
my html code is this: <input type="text" name="curname" id="exRate" value="<?php echo($currency); ?>" onClick="upActive()"> textbox name is given as array. how can i validate all...
2
by: poops2468 | last post by:
Sorry if this is a totally newbie question, but I haven't found a decent answer. I am using VS 2008. I have a DataGridView on a Windows Form. First, I want to validate that the input in the...
8
by: chandhseke | last post by:
Hi Team, I have designed a dynamic form with number of elements, i am stuck with a requirement where i need your help. The requirement is : While a user fills out the form, one particular text...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.