Forum Moderators: open

Message Too Old, No Replies

Reconfiguring a JavaScript filter to accept 4 character domains

Currently the JavaScript only filters emails with 2 or 3 char. extensions

         

jomoweb

4:42 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Im not much of a programmer, so I can't figure this one out. The code I am trying to fix only accepts domain extensions with 3 letters like .com or .net. I just realized it won't let people enter emails like .info or .coop because they are 4 characters. Can someone help me? Code:

if (custForm.Phone.value.length==0)
{alert('Day time phone number is required.')
document.custForm.Phone.focus()
return false}
[b]str=document.custForm.EMail.value
filter=/^.+@.+\..{2,3}$/[/b]

if (!filter.test(str))
{alert('Please input a valid email address!')
document.custForm.EMail.focus()
return false}


Thanks,
JoMo

j4mes

4:47 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Only a guess, but have you tried replacing

filter=/^.+@.+\..{2,3}$/

with

filter=/^.+@.+\..{2,3[red],4[/red]}$/

?

jomoweb

5:10 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Yeah, I tried that already, and it didnt work, when I plugged in ,4 it wouldnt even work for 3 char emails.

RonPK

5:11 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try

filter=/^.+@.+\..{2,4}$/

There is a .museum TLD, so to be really 100% safe you could use filter=/^.+@.+\..{2,6}$/ , but I've never seen such an address in the wild.

jomoweb

5:22 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Ron it worked! Is it b/c 2,4 describes an array of integers with the comma in the middle?

The customer that complained was actually a .coop email. Haven't heard of that one or seen it in the wild either.

Thanks

RonPK

5:40 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, it specifies the range. {2,5} means "match the preceding character from 2 up to 5 occurences".

You might improve the pattern a bit by using this:

filter=/^.+@.+\.[a-z]{2,4}$/i

2 modifications:
* replaced a . with [a-z]. The dot stands for any character, including digits and punctuation chars. TLDs off course should only consist of letters, and that is what the [a-z] thing does.
* added the i-switch to the end of the pattern, to make it case-insensitive.

jomoweb

5:49 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Thanks again Ron. I don't want to make it case sensitive, because we get a lot of people ordering product with the caps lock on, but I think I will change the other part.

encyclo

6:59 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not a Javascript guru either, but does this script take into account domain names with a second level domain, such as .qc.ca or .com.au? Many country domains use this approach.

I believe in most cases the string before the country code is not longer than three letters, but in rare instances it can be longer: .police.uk is one example.

jomoweb

7:20 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



I tried a multi-tiered domain with .com.au to test and it did work. Thanks for the thought though, b/c we are getting more and more international orders, and many international customers have domaines like this.