![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| Hi All, I've added a line to make sure the email address is not blank...but I can't get the validation part working. if i uncomment the commented lines in red, i get the error: error '8004020e' ...this has to do with validation when i google. am i using that validator the wrong way? ![]() Code: <script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
if (formDOMObj.EqNo.value == "")
alert("Please enter EQNumber!")
if (formDOMObj.EqDesc.value == "")
alert("Please enter EQDescription!")
if (formDOMObj.EmailAdd.value == "")
alert("Please enter your email address!")
// if (emailValidator(formDOMObj.EmailAddress.value,"Please enter a valid email address")) else
return true;
return false;
}
//function emailValidator(){
// var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
// if(formDOMObj.EmailAdd.match(emailExp)){
// return true;
// }
//else{
// return false;
// }
//}
</script>
|
| Sponsored Links |
|
#2
| ||||
| ||||
| okay, my javascript is not the greatest. but try something like this Code: <script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if (formDOMObj.EqNo.value == "")
alert("Please enter EQNumber!")
if (formDOMObj.EqDesc.value == "")
alert("Please enter EQDescription!")
if (formDOMObj.EmailAdd.value == "")
alert("Please enter your email address!")
if (!(formDOMObj.EmailAdd.match(emailExp)))
alert("Please enter a valid email address")
return false;
}
</script>
__________________ Quote of the Month: Regret: It hurts to admit when you make mistakes - but when they're big enough, the pain only lasts a second. Questions to Ponder: Could it be that all those trick-or-treaters wearing sheets aren’t going as ghosts but as mattresses? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright © 2008 sbenj69 |
| The Following User Says Thank You to mehere For This Useful Post: | ||
Rebelle (August 21st, 2008) | ||
|
#3
| ||||
| ||||
| You'll need to return true at some point or the form won't submit. Using mehere's example, try this:- Code: function onSubmitForm() {
var formDOMObj = document.frmSend;
var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
if (formDOMObj.EqNo.value == ""){
alert("Please enter EQNumber!");
return false;
}
if (formDOMObj.EqDesc.value == ""){
alert("Please enter EQDescription!");
return false;
}
if (!emailExp.test(formDOMObj.EmailAdd.value)){
alert("Please enter a valid email address");
return false;
}
return true;
}
</script>
Hope that helps. <edit>I couldn't get it to work using \w. You could try this expression "^[A-Za-z0-9\-.+]+@[A-Za-z0-9.-]+[.]+[A-Za-z]{2,4}$" That will only accept email addresses in the format name@domain.ext You may want to accept emails with name@domain in which case change +[.] to +\. </edit> Last edited by richyrich; August 20th, 2008 at 02:49 PM. |
| The Following User Says Thank You to richyrich For This Useful Post: | ||
mehere (August 20th, 2008) | ||
|
#4
| ||||
| ||||
| Thanks Mehere & RR.... RR, I tried the below but it didn't work, kept getting error 8004020e...and it no longer alerted for the other fields. So, the only way to not get the error was to comment out the lines. ![]() Code: <script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
// var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
if (formDOMObj.EqNo.value == ""){
alert("Please enter EQNumber!");
return false;
}
if (formDOMObj.EqDesc.value == ""){
alert("Please enter EQDescription!");
return false;
}
// if (!emailExp.test(formDOMObj.EmailAdd.value)){
// alert("Please enter a valid email address");
// return false;
// }
return true;
}
</script>
like below:Code: <script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if (formDOMObj.EqNo.value == ""){
alert("Please enter EQNumber!");
return false;
}
if (formDOMObj.EqDesc.value == ""){
alert("Please enter EQDescription!");
return false;
}
if (!emailExp.test(formDOMObj.EmailAdd.value)){
alert("Please enter a valid email address");
return false;
} return true;
}
</script>
Quote:
|
|
#6
| ||||
| ||||
| hmmm...not sure...maybe asp? error '8004020e' the line is 222 which is from my cdo code... this line: Code: .Send |
|
#7
| ||||
| ||||
| That is an error with CDO, normally related to an invalid email address. When you uncomment the JS code and enter something like 'Rebelle' in the email text box, what happens? |
|
#8
| ||||
| ||||
| Hi RR, If i uncomment the line and enter Rebelle...I don't get the error but I also leave the other fields blank so i could get alert but I don't get the alerts..... it's when i leave the email address field blank that I get the error......but when i leave the other fields blank too, i don't get any alerts....just the error. |
|
#9
| ||||
| ||||
| The speech marks are missing off this line:- Code: var emailExp = "/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$"; Code: var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
Last edited by richyrich; August 21st, 2008 at 09:19 AM. |
|
#10
| ||||
| ||||
| ok...i retried and retried with the original line but same thing kept happening. so I tried changing the " and " to / and / ... like below: from: Code: var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
Code: var emailExp = new RegExp(/^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/);
|
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| validation | todd2006 | JavaScript Programming | 5 | July 30th, 2008 09:23 AM |
| date validation | todd2006 | JavaScript Programming | 3 | July 6th, 2008 11:39 AM |
| textbox validation | todd2006 | JavaScript Programming | 6 | July 2nd, 2008 01:30 PM |
| checkbox validation | todd2006 | JavaScript Programming | 3 | June 18th, 2008 07:22 PM |
| [ASP.Net/VB.Net] Programmatically Add Item to Validation Summary | jmurrayhead | Code Samples | 0 | March 20th, 2008 09:41 AM |