PDA

View Full Version : Regular Expression



Happy_davood
پنج شنبه 25 فروردین 1384, 00:36 صبح
سلام
می خواستم بدونم چطوری میشه محتوای یک تکست باکس رو به صورت regular Expression تست کرد . مثلاً صحت آدرس ایمیل رو ؟
ممنون

علیرضا جاوید
شنبه 27 فروردین 1384, 00:17 صبح
<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<! >

<!-- Begin
var good;
function checkEmailAddress(field) {
// the following expression must be all on one line...
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.go v)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail) {
good = true;
}
else {
alert('Please enter a valid e-mail address.');
field.focus();
field.select();
good = false;
}
}
u = window.location;
m = "I thought this might interest you...";
function mailThisUrl() {
good = false
checkEmailAddress(document.eMailer.address);
if (good) {
// the following expression must be all on one line...
window.location = "mailto:"+document.eMailer.address.value+"?subject="+m+"&body="+document.title+" "+u;
}
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form name="eMailer">
E-MAIL THIS LINK
<br>
Enter recipient's e-mail:
<br>
<input type="text" name="address" size="25">
<br>
<input type="button" value="Send this URL" onClick="mailThisUrl();">
</form>