Email Validation script

Description: This script uses regular expressions to check that
a form field contains a valid email address. Note that it won't catch all invalid
emails, like most similar scripts. However, for most intents and purposes, this
script should serve its purpose well, by rejecting common email typos while leaving
room for obscure yet valid emails to pass.

Here are some examples of valid email addresses that this script will recognize:

---contact@mydomain.com

---jason+lang@gmail.com

---help@nbc.co.uk

---mary.k.ashley@celeb.com

---george@sub.whatever.mydomain.ca

---edward@42.234.12.345


Step 1: Add the below script to the <BODY> section of
your page:


<script type="text/javascript">


/***********************************************

* Email Validation script- © Dynamic Drive (www.dynamicdrive.com)

* This notice must stay intact for legal use.

* Visit http://www.dynamicdrive.com/ for full source code

***********************************************/


var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i


function checkmail(e){

var returnval=emailfilter.test(e.value)

if (returnval==false){

alert("Please enter a valid email address.")

e.select()

}

return returnval

}


</script>


<form>

<input name="myemail" type="text" style="width:
270px"> <input type="submit" onClick="return checkmail(this.form.myemail)"
value="Submit" />


</form>


The code above includes a sample form where this script validates the email
field contained. The form looks like this:



<form>

<input name="myemail" type="text" style="width:
300px"><br/>

<input type="submit" onClick="return checkmail(this.form.myemail)"
value="Submit" />

</form>


To customize this script to serve your own form(s), simply change the parts
in red above to your own. More specifically, you should first give your email
address field a name(ie: name="myemail"). Then, modify the submit
button of the form by adding in the "onClick" portion. Remember to
change "myemail" to reflect the name of your email address field.


[+/-] More...

Form field Limiter v2.0

Note: Updated Feb 25th, 09'. Script rewritten for various improvements.

Description: Want to limit the amount of text a user can enter
in particular INPUT type="text" or TEXTAREA elements? Well, this script
enables not only that, but displays in real time the number of characters remaining.
A callback function enables you to define your own actions when the field limit
has been reached, such as apply a red border around the field in question.


Step 1: Add the below script to the <HEAD> section of
your page:


<script type="text/javascript" src="formfieldlimiter.js">
/***********************************************

* Form field Limiter v2.0- © Dynamic Drive DHTML code library (www.dynamicdrive.com)

* This notice MUST stay intact for legal use

* Visit Project Page at http://www.dynamicdrive.com for full source code

***********************************************/



</script>


The above references the following .js file, which you should download: formfieldlimiter.js.



Step 2: Then, insert the below sample form onto your page,
which contains two sample fields- a text and textarea field- with the script
applied to them:



<form name="sampleform"">


<input type="text" name="george" style="width:250px"
/>

<div id="george-status"></div>


<p>

<textarea name="johndoe" id="johndoe" cols="30"
rows="5" style="width:250px"></textarea>

<div id="john-status"></div>



</form>



<script type="text/javascript">


//Example 1:


fieldlimiter.setup({

thefield: document.sampleform.george, //reference to form field

maxlength: 10,

statusids: ["george-status"], //id(s) of divs to output characters
limit in the form [id1, id2, etc]. If non, set to empty array [].

onkeypress:function(maxlength, curlength){ //onkeypress event handler

if (curlength<maxlength) //if limit hasn't been reached

this.style.border="2px solid gray" //"this" keyword returns
form field

else

this.style.border="2px solid red"

}

})


//Example 2:


fieldlimiter.setup({

thefield: document.getElementById("johndoe"), //reference to form
field

maxlength: 30,

statusids: ["john-status"], //id(s) of divs to output characters limit.
If non, set to empty array [].

onkeypress:function(maxlength, curlength){ //onkeypress event handler

//define custom event actions here if desired

}

})


</script>


Customization


To apply the script to any INPUT type="text" or TEXTAREA within a form,
call fieldlimiter.setup() with the desired settings following the field's HTML,
for example:



<form name="sampleform"">



<input type="text" name="george" style="width:250px"
/>

<div id="george-status"></div>



</form>



<script type="text/javascript">



fieldlimiter.setup({

thefield: document.sampleform.george, //reference to form field

maxlength: 10,

statusids: ["george-status"], //id(s) of divs to output characters
limit in the form [id1, id2, etc]. If non, set to empty array [].

onkeypress:function(maxlength, curlength){ //onkeypress event handler

//define custom event actions here if desired

}

})



</script>


A good place to call fieldlimiter.setup() if you wish to consolidate things
is at the very end of your document. The setting "thefield" should
be a reference to the desired form field, which you can do either by name (ie:
document.formname.fieldname), or if it contains an ID attribute, by ID if you
like (ie: document.getElementById("george"). The setting "statusids"
allows you to define a list of container IDs that will display in real time
the number of characters left for the form field. Make sure the actual container(s)
is defined on the page, such as <div id="george-status"></div>.




onkeypress event handler


The final setting, "onkeypress", makes it possible to define custom
code that is fired each time the user presses a key inside the form field in
question. Together with a couple of parameters entered into it, plus the "this"
keyword inside the function that returns a reference to the form field, you
can, for example, perform a certain action whenever the user has reached the
field's limit:


onkeypress:function(maxlength, curlength){ //onkeypress event handler

if (curlength<maxlength) //if limit hasn't been reached

this.style.border="2px solid gray" //"this" keyword returns
form field

else

this.style.border="2px solid red"

}


The parameters "maxlength" and "curlength" informs you
of the field limit plus current number of characters entered, respectively.
The "this" keyword returns as a DOM object the form field in question.
In the above example, the field gets a red border whenever the user has exceeded
the limit.

[+/-] More...

Glowing Text Script

Description: Add flare and draw attention to important text
on your page by making them glow! The below script utilizes the glow filter
of DHTML to first surround any text with a yellow "light", then uses
scripting to make the light "come alive" and glow (look closely...the
light is actually moving!). Poor folks not using IE 4+ will simply see the text
in its usual, dull state.


Try using the above script on a page with black background and white text;
it'll fit the Halloween mood quite nicely! (For reference in the future, this
page was created near the advent of Halloween :-)


Step 1: Insert the below into the <head> section of your page:


<style>
<!--
#glowtext{
filter:glow(color=FFFF00,strength=3);
width:100%;
}
-->
</style>

<script language="JavaScript1.2">

/*
Glowing Text Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function glowit(which){
if (document.all.glowtext[which].filters[0].strength==3)
document.all.glowtext[which].filters[0].strength=2
else
document.all.glowtext[which].filters[0].strength=3
}

function glowit2(which){
if (document.all.glowtext.filters[0].strength==3)
document.all.glowtext.filters[0].strength=2
else
document.all.glowtext.filters[0].strength=3
}

function startglowing(){
if (document.all.glowtext&&glowtext.length){
for (i=0;i<glowtext.length;i++)
eval('setInterval("glowit('+i+')",150)')
}
else if (glowtext)
setInterval("glowit2(0)",150)
}

if (document.all)
window.onload=startglowing
</script>

 


if you wish to change the color of the glow (from yellow to something else), just
change FFFF00 inside the <style> tag.

Step 2: Now, to fire up some text, wrap it with the below
span tag:

<span id="glowtext">This
is a glowing text</span>

[+/-] More...

Flying Letters

Description: Animate your site's header into view, one letter
at a time, with this one-of-a-kind script! Tested in Firefox 1.0.7, Opera 8.51,
Konqueror 3.5.0-1.2 and IE 6.


Simply add the below code to the <BODY> of your page:



<h2 id="fly">Thanks for visiting$Dynamic Drive!</h2>


<script type="text/javascript">


//Flying Letters script- by Matthias (info@freejavascripts.f2s.com)

// Modified by Twey for efficiency and compatibility

//For this script and more, visit Dynamic Drive: http://www.dynamicdrive.com


//Configure message to display. Use "$" for linebreak

//By default, set to just grab the text from element with ID="fly"

message = document.getElementById("fly").innerHTML; // $ = taking
a new line

distance = 50; // pixel(s)

speed = 200; // milliseconds


var txt="",

num=0,

num4=0,

flyofle="",

flyofwi="",

flyofto="",

fly=document.getElementById("fly");




function stfly() {

for(i=0;i != message.length;i++) {

if(message.charAt(i) != "$")

txt += "<span style='position:relative;visibility:hidden;' id='n"+i+"'>"+message.charAt(i)+"<\/span>";

else

txt += "<br>";

}

fly.innerHTML = txt;

txt = "";

flyofle = fly.offsetLeft;

flyofwi = fly.offsetWidth;

flyofto = fly.offsetTop;

fly2b();

}


function fly2b() {

if(num4 != message.length) {

if(message.charAt(num4) != "$") {

var then = document.getElementById("n" + num4);

then.style.left = flyofle - then.offsetLeft + flyofwi / 2;

then.style.top = flyofto - then.offsetTop + distance;

fly3(then.id, parseInt(then.style.left), parseInt(then.style.left) / 5, parseInt(then.style.top),
parseInt(then.style.top) / 5);

}

num4++;

setTimeout("fly2b()", speed);

}

}


function fly3(target,lef2,num2,top2,num3) {

if((Math.floor(top2) != 0 && Math.floor(top2) != -1) || (Math.floor(lef2)
!= 0 && Math.floor(lef2) != -1)) {

if(lef2 >= 0)

lef2 -= num2;

else

lef2 += num2 * -1;

if(Math.floor(lef2) != -1) {

document.getElementById(target).style.visibility = "visible";

document.getElementById(target).style.left = Math.floor(lef2);

} else {

document.getElementById(target).style.visibility = "visible";

document.getElementById(target).style.left = Math.floor(lef2 + 1);

}

if(lef2 >= 0)

top2 -= num3

else

top2 += num3 * -1;

if(Math.floor(top2) != -1)

document.getElementById(target).style.top = Math.floor(top2);

else

document.getElementById(target).style.top = Math.floor(top2 + 1);

setTimeout("fly3('"+target+"',"+lef2+","+num2+","+top2+","+num3+")",50)

}

}


stfly()


</script>


 


[+/-] More...

Search here

Other Link