/    Sign up×
Community /Pin to ProfileBookmark

string manimpulation/validation + javascript

I am lost on this. Please help. I want to validate the text field (“manemail”) has “viropharma.com” at the end. If not, an alert will pop up.
I know I have this code using “substring” wrong. Please help.

checkEmail = form.manemail.value

if ((checkEmail.substring(‘xyz.com’) =0)
{alert(“Need xyz.com”);
form.manemail.select();
return false;
}

Thanks!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Jan 31.2003 — 
checkEmail = form.manemail.value

if ((checkEmail.substring('xyz.com') =0)

{alert("Need xyz.com");

form.manemail.select();

return false;

}
[/QUOTE]


set the condition to >-1 instead of =0

if ((checkEmail.substring('xyz.com') >-1)


cheers

Khalid
Copy linkTweet thisAlerts:
@peach255authorJan 31.2003 — thanks for your help, but this did not work:

if ((checkEmail.substring('xyz.com') >-1)

I thought for substring, you need substring(from,to), and from and to are # positions.

Is there another way I can easily do this?

thanks!
Copy linkTweet thisAlerts:
@CharlesJan 31.2003 — [i]Originally posted by peach255 [/i]

[B]I thought for substring, you need substring(from,to), and from and to are # positions.[/B][/QUOTE]
[font=georgia]No, that's optional. See http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm#1194665.

Another way to do this would be to use:[/font]

[font=monospace]

<font action="someScript.pl" onsubmit="if (!/xyz.com$/.test(this.manemail.value)) {alert('Need 'xyz.com'.'); this.manemail.value=''; this.mainmail.focus(); return false}">

[/font]
Copy linkTweet thisAlerts:
@peach255authorJan 31.2003 — think I'm close ... but no cigar yet. any idea? It just seems to bypass this script.


checkEmail = form.manemail.value

atsymbol = checkEmail.indexOf('@');

domainstart = atsymbol + 1;

wholedomain = checkEmail.substring(domainstart,checkEmail.length);

if (wholedomain <> "xyz.com");

{

alert('Need xyz.com');

form.manemail.select();

return false;

}
Copy linkTweet thisAlerts:
@CharlesJan 31.2003 — [font=georgia]How about trying my suggestion? And check out that link I gave above.

I think your problem has to do with your form itself. It's just a hunch, but a link to the page might be helpful.[/font]
Copy linkTweet thisAlerts:
@khalidali63Jan 31.2003 — If you are hard coding a condition for a certain email address then that should be piece of cake.and your condition

if ((checkEmail.substring('xyz.com') >-1)

will have to work.

If you are getting a random string and only checking fora a valid email account then you may want to check this link below,

http://68.145.35.86/skills/javascripts/EmailValidator.html

Otherwise you must have to validate your text entry from the form( as charles mentioned above).
×

Success!

Help @peach255 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...