473,569 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use javascript to do a " flexiable" validation

88 New Member
hi

now i am using javascript to do a "flexiable" validaion, what i mean "flexiable" is user can choose which one they would like fill in in the bank but at least they must enter one.
in my page, i offered three kind of phone NO to let user enter in, one is Home phone NO, the other is Hand phone NO, the last one is Office Pone No. they can enter in "one or More" of these phone NO.

however my validation have problem and i cant probably check the correctness of their phone no.
the following is my current javascript

Expand|Select|Wrap|Line Numbers
  1. :
  2.  
  3. <script language="JavaScript">
  4.  
  5. <!--
  6.  
  7. function validate_form ( )
  8. {
  9.     valid = true;
  10.     if ( document.regForm.uName.value == "" )
  11.     {
  12.         alert ( "Please fill in the 'Your name' box." );
  13.         regForm.uName.focus();
  14.         valid = false;
  15.     }
  16.  
  17.  else if ( ( document.regForm.Hphone.value=="" )
  18.     && ( document.regForm.HP.value =="") && ( document.regForm.Ophone.value == "") )
  19.     {
  20.         alert ( "Please enter any one of the three phone NO" );
  21.         valid = false;
  22.  
  23.         if ( ((/^(\((\+\d{2})?\))?[56]\d{7}$/).test(regForm.Hphone.value) ==true)){
  24.         alert ( "the Home phone No entered is not valid" );
  25.         valid = true;
  26.         }
  27.  
  28.         else if (((/^(\((\+\d{2})?\))?[89]\d{7}$/).test(regForm.HP.value) ==true)){
  29.              alert ( "the HP phone No entered is not valid" );
  30.         valid = true;
  31.             }
  32.  
  33.             else if (((/^(\((\+\d{2})?\))?[3456]\d{7}$/).test(regForm.Ophone.value) ==true)){
  34.              alert ( "the Office phone No entered is not valid" );
  35.         valid = true;
  36.         }
  37.  
  38.  
  39.     }
  40.  
  41.        return valid;
  42. }
  43.  
  44.  
  45. //-->
  46. </script>
i have tired very hard to do this, but it seems just cant work well, can anyone help me with this. i would like to solve this ASAP as the project deadline is near the corner. thanks in advance
Jul 7 '07 #1
4 1343
pbmods
5,821 Recognized Expert Expert
Moving to JavaScript....
Jul 7 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
You need to close the else-if started on line 17 on line 22.
Jul 9 '07 #3
kang jia
88 New Member
You need to close the else-if started on line 17 on line 22.
in fact, i have a nested if ..else inside this else if { ...}
the code is in the following ( i only take out the part i got problem with):

Expand|Select|Wrap|Line Numbers
  1.  
  2.   else if ( ( document.regForm.Hphone.value=="" )
  3.     && ( document.regForm.HP.value =="") && ( document.regForm.Ophone.value == "") )
  4.     {
  5.         alert ( "Please enter any one of the three phone NO" );
  6.         valid = false;
  7.  
  8.     if ( ((/^(\((\+\d{2})?\))?[56]\d{7}$/).test(regForm.Hphone.value) ==true)){
  9.         alert ( "the Home phone No entered is not valid" );
  10.         valid = true;
  11.         }
  12.  
  13.         else if (((/^(\((\+\d{2})?\))?[89]\d{7}$/).test(regForm.HP.value) ==true)){
  14.              alert ( "the HP phone No entered is not valid" );
  15.         valid = true;
  16.             }
  17.  
  18.             else if (((/^(\((\+\d{2})?\))?[3456]\d{7}$/).test(regForm.Ophone.value) ==true)){
  19.              alert ( "the Office phone No entered is not valid" );
  20.         valid = true;
  21.         }
  22.  
  23.     }
  24.  
it seems did not validate wrong entered NO, and i would like it to be flexible, which means user can choose which one they want to enter among these three phone NO.

if possible, can reply as ASAP as my project time line is near, it is a bit urgent. thanks for your kind help :)
Jul 10 '07 #4
acoder
16,027 Recognized Expert Moderator MVP
Try:
Expand|Select|Wrap|Line Numbers
  1. ...test(document.forms["regForm"].OPhone.value // and so on
Jul 11 '07 #5

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

Similar topics

3
2270
by: NotGiven | last post by:
I have a web form with several fields. If I copy & paste from a RTF document into a field, the javascript validation and field length are bypassed and cause the form to fail. Any ideas?
5
2572
by: JJ_377 | last post by:
I want a JavaScript validation function to fire on an ASP.NET textbox's change event. Here's what I've been trying and it is not working. The following added in the webform's page load event: txtBirthdate.Attributes.Add("txtBirthdate_TextChanged", "MyJSFunction()") txtBirthdate.Attributes.Add("TextChanged", "MyJSFunction()")
3
1712
by: Mike P | last post by:
I have a method that I use for Javascript validation (see below). What I want to do is change the alert title, buttons, icon etc. Does anybody know the correct syntax to do this? private void Gen_Alert(string Key, string msg) { string str = ""; str += "<script language='javascript'>"; str += "alert('"+msg+"')"; str += "</script>";
1
1926
by: karen987 | last post by:
I have a comment form, on a news website, ASP page, which users fill in and it adds comments to a news article. The reader clicks on a headline and the comments open up in a new window. It already has server side validation in but i want to add some client side javascript validation. How can do i this when there is alreay a "returnvalidate...
1
1645
by: ll | last post by:
Hi, I am working with a page that has both cfform elements and 'plain html' form elements. In particular, I am needing to validate my textarea form field and my email text field. On one of my html pages, I have been using a great javascript validation script; however, I am wondering if I can use that in a coldfusion page? I've included the...
1
1629
by: shrin | last post by:
Hi all, I want to use asp.net validator and javascript validation function on a single form for different fields. also I want to execute some code on button click after the validation is completed. My problem is that when i click on the button at first instacne it execute the javascript function however when page load event occures the error...
21
16866
by: kiran83 | last post by:
My Text box can accept all types of data like alphabets,numeric,special characters ... Should give an error message 'if space is not a valid value ' when i am clicking a button... in asp.net with c# through javascript.(javascript validation after clicking a button).
1
2755
by: jerrydigital | last post by:
Hello, I have a form that i use ASP to process the form to my access database. It works well but I'm struggling to get the javascript validation to work. I have posted a small version of my form to see if any of you know why this isn't working. I believe this is supposed to have a box pop up to say "You must enter a first name." when you...
12
9888
by: btreddy | last post by:
Hii Experts, im facing a problem with the javascript validation.i've a gridview in my web form and added a footer tempalte and placed textboxes in tht tempalte ,just to add a new row to the gridview and i wanna to validate the emalid entered in the footertextbox of the gridview. so i added a javasript function : function...
3
2786
by: gayuvinu | last post by:
Hi, I am new to javascript, I need your help in javascript validation of a string. string of length 6, last 4 characters can be padded with "8" while entering. valid strings are ZJJL74 ZJJL7* ZJJL** ZJJ*** ZJ****
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6281
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.