Sunday, December 23, 2007

Email Validation

Here is a sample code for validating email address using JavaScript regular expression.

var Email = "username@domain.com";
var flag = /^[a-zA-Z0-9_.]+@[a-zA-Z0-9]+[.][a-zA-Z]+[a-zA-Z.]*$/.test(Email);
if(flag){
alert('Valid email address');
}else
alert('Invalid email address');

Saturday, December 1, 2007

Find Position

Each html elements in a page has position values (ie. where the elements currently
placed). Basically it is measured by pixels from top and pixels from left.The top
and left position values are obtained by using the html elements attributs offsetTop
and offsetLeft.This can be calculated at run time using javascrit.
The script follows. Argument of the function is the object of the HTML element,
and it returns the array of values.

function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}

Yahoo! News: Technology News