473,386 Members | 1,773 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,386 software developers and data experts.

Problem in email validation

Hi,
I am trying to validate my form email field if i gave condition for empty field its working then again i checked whether the email id is valid one or not but its working but if i give valid id that time also it displays the alert box only

can anyone tell me wat problem in my code
here is the code
Expand|Select|Wrap|Line Numbers
  1.  
  2. function validate()
  3. {
  4. var emailid=document.getElementById('email')
  5. var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
  6. if(emailid.value.length==0)
  7. {
  8. alert("Must to enter email id");
  9. emailid.focus()
  10. return false;
  11.  }
  12. if (!emailid.match(emailPat)) {
  13. alert("Your email address seems incorrect.  Please try again (check the '@' and '.'s in the email address)");
  14. return false;
  15.    }
  16. }
  17.  </script>
  18.  
Jul 31 '07 #1
2 1390
vee10
141 100+
Hi ,

the problem in ur code is at the last if conditon

if (!emailid.match(emailPat))

it should be

if (!(emailid.value.match(emailPat)))

regards


Hi,
I am trying to validate my form email field if i gave condition for empty field its working then again i checked whether the email id is valid one or not but its working but if i give valid id that time also it displays the alert box only

can anyone tell me wat problem in my code
here is the code
Expand|Select|Wrap|Line Numbers
  1.  
  2. function validate()
  3. {
  4. var emailid=document.getElementById('email')
  5. var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
  6. if(emailid.value.length==0)
  7. {
  8. alert("Must to enter email id");
  9. emailid.focus()
  10. return false;
  11.  }
  12. if (!emailid.match(emailPat)) {
  13. alert("Your email address seems incorrect.  Please try again (check the '@' and '.'s in the email address)");
  14. return false;
  15.    }
  16. }
  17.  </script>
  18.  
Jul 31 '07 #2
Hi,
Mycode is working now
thanks

Hi ,

the problem in ur code is at the last if conditon

if (!emailid.match(emailPat))

it should be

if (!(emailid.value.match(emailPat)))

regards
Jul 31 '07 #3

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

Similar topics

2
by: Shahar | last post by:
hi I have the following problem: I have two button, tow textboxes and two RequiredFieldValidator controls, like that: <form id="Form1" method="post" runat="server"> <asp:TextBox id="TextBox1"...
5
by: Jim Brandley | last post by:
I have a required field with a client-side validator. It works as advertised until I try to add code to block double submits and replace the image on the submit button to give the users some...
2
by: Bobby | last post by:
Hi all, I want to validate my page with ASP.NET Validator controls. It works well, but I have 2 form in one page. My problem is that, If I input form1, and I click submit, It will also validate...
5
by: excelleinc.com | last post by:
Hello, I have 2 forms to be filled by user, one is "auth" and second one contact form. They're completely independent. Problem is that when I enclose them within same <form runat="server"> tag...
3
by: john morales | last post by:
Hi guys, I have a problem and i know there must be a solution for this as it is such a basic common practice in asp.net development. Scenario: i have many webforms in a site, most with two...
3
by: msnews.microsoft.com | last post by:
Hi All, I m facing problem in Server Side Validation. For Example The Scenario is I have two fields on the page 1 Country Dropdown List 2 Province Textbox 3 State Dropdown List
3
by: Tarun Upadhyaya | last post by:
Hi, I am facing strange problem I read Scott mitchell's article about ASP.NET and javascript at ...
3
by: aljodo | last post by:
ASP.Net v1.1 & vb.net Hi all, I have a simple survey form with first name/last name text boxes at the top. I have validators on these text boxes to ensure that something is entered in them. ...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
2
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.