473,406 Members | 2,371 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,406 software developers and data experts.

Javascript validation code errors, problems and bugs

114 100+
Can someone please tell me how to alter this code if it needs altering, . thanks in advance.


1. The form keeps focusing on "username" and won't submit. The 2 username functions may be clashing? i want the username to be letters and numbers only , no special characters or spaces, 5-18 characters.

2. The country is a drop down list, and they must select one. I think since it is a drop down i don't need the function which checks for blanks and empty? or do i? or maybe it should be altered?

3. The opt15 function if for a mandatory checkbox,


4.. That the closing brackets at the end are correct?

The problems may well be very simple omissions, i'm not html literate. these are ASP pages by the way.


Expand|Select|Wrap|Line Numbers
  1.    if (String(frm.username.value).replace(/ /g, "") == "")  {
  2.          alert("Please enter desired username. Must be between 5-25 characters (no special characters).")
  3.          document.frm.username.focus() ;
  4.         return false; }
  5.  
  6.   var regExp = /^[A-Za-z][A-Za-z0-9_]*$/;
  7.    if(!regExp.test(frm.username.value))
  8.      alert("no special characters or spaces in 'username'")
  9.    if(frm.username.value.length > 18 || frm.username.value.length < 5)
  10. alert("'Username' should be between 5-18 characters.")
  11.  for(i=0;i<frm.username.value.length;i++) {
  12.  document.frm.username.focus() ;
  13.    return false; }
  14.  
  15.  
  16. if (String(frm.country.value).replace(/ /g, "") == "")  {
  17.          alert("Please enter your country.")
  18.          document.frm.country.focus() ;
  19.         return false; }
  20.  
  21.   if(document.frm.country.value.length < 2) {  
  22.    alert("Minimum 2 characters for 'country'.")
  23.   document.frm.country.focus() ;
  24.    return false; }
  25.  
  26.    if(document.frm.country.value.length > 20) {  
  27.    alert("Maximum 20 characters allowed for 'country'.")
  28.   document.frm.country.focus() ;
  29.    return false; }
  30.  
  31.    var mycheckbox = document.frm.opt15; 
  32. if (mycheckbox.checked == false) { 
  33.    alert("this checkbox is mandatory") 
  34.    return false; 
  35.    return true; 
  36.     } 
Apr 29 '07 #1
2 1597
iam_clint
1,208 Expert 1GB
first problem
Expand|Select|Wrap|Line Numbers
  1.    if(frm.username.value.length > 18 || frm.username.value.length < 5)
  2. alert("'Username' should be between 5-18 characters.")
  3.  for(i=0;i<frm.username.value.length;i++) {
  4.  document.frm.username.focus() ;
  5.    return false; }
  6.  
  7.  
Expand|Select|Wrap|Line Numbers
  1. if(frm.username.value.length > 18 || frm.username.value.length < 5)  {
  2. alert("'Username' should be between 5-18 characters.")
  3. document.frm.username.focus() ;
  4. return false; }
  5.  
Apr 30 '07 #2
karen987
114 100+
thank you, IamClint. appreciated.
Apr 30 '07 #3

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

Similar topics

8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
61
by: shapper | last post by:
Hello, I would like to use a javascript library to simplify my coding process. I know a few: JQuery, Dojo, Yahoo UI, ... Which one do you advice me to use? Thanks, Miguel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.