Monday, November 27, 2006

Password Validation

When it comes to password validation using regular expressions, things can get a bit complicated. Normally, you want people to enter a "good" password that has a mix of numbers and letters. But you may not care where the numbers and letters appear. So you're not looking for a "pattern" in the string. You just want a letter somewhere and a number somewhere.

In this first example, the password must be at least 8 characters long and start and end with a letter.

var re = /^[A-Za-z]\w{6,}[A-Za-z]$/;
if (!re.test(myString)) { alert("Please enter a valid password!"); }

The ^ looks for something at the start of the string. The brackets indicate the valid character set. So it must start with an upper or lower case letter. After that, the \w means there can be valid alphanumeric characters (numbers 0-9, upper/lower case letters a-z, the underscore) and says there must be at least 6 (but no upper limit). Then comes another set and the $ looks for something at the end of the string. So this statement says there must be a letter, then at least 6 of any alphanumeric characters, then a letter (making 8 the minimum number of characters).

In this second example, the password length doesn't matter, but the password must contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter.

var re = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/
if (!re.test(myString)) { alert("Please enter a valid password!"); }

Again, the ^ and $ are looking for things at the start and end. The "\w*" combination is used at both the start and the end. \w means any alphanumeric character, and * means zero or more. You'll see why it's "zero or more" in a bit. Between are groupings in parentheses. The "(?" combination is a flag in regular expressions. Basically, they say "apply the following formula, but don't consume any of the string". In this example, instead of specifying the order that things should appear, it's saying that it must appear but we're not worried about the order.

The first grouping (called an "atom" in "regular expresion speak") uses the = sign. This means that there must be a match. Other choices are ! for a negative match (the string must not look like this). There are others (more complicated) for preceeding matches and stuff. We can refer you to a regular expression syntax web site for further details.

After the = sign comes "\w*\d". Again, any alphanumeric character can happen zero or more times, then any digit (\d means any digit from 0 to 9) can happen. So this checks to see if there is at least one number in the string. But since the string isn't comsumed, that one digit can appear anywhere in the string.

The next atom (grouping) is (?=\w*[a-z]). This is similar to the digit grouping, except it looks for a lower case letter. Again, the lower case letter can appear anywhere, but there has to be at least one.

The third atom is (?=\w*[A-Z]) which looks for an upper case letter somewhere in the string.

Finally, at the end is zero or more alphanumeric characters. To match this string, the minimum characters needed is 3 (one upper case letter, one lower case letter, and one number).

http://www.breakingpar.com/bkp/...

Saturday, November 25, 2006

How to make a dynamic TOOLTIP

Popup a help tip or information layer onmouseover using this object-based DHTML tooltip code. The basic version, presented on this page, can contain plain text or rich html, images, or images and text. The tooltip can be displayed over a background image. It can move with mouse movement. And it is easy to customize and modify.
Content to be displayed in the tooltip can be passed from the onmouseover event handler itself, or it can be contained in global variables or arrays, or it can be dynamically generated, for example, from database query results.


For Eg visit: http://www.dyn-web.com/dhtml/tooltips/

How to create popup on defined size for an hyperlink

Lets asume we have an asp hyperlink control named/id "HyperLink_Download" in your page. And when u click it u want to open a popup with a defined size in another window, and it should not show the link properties in status bar.


Here is an example.
HyperLink_Download.Attributes.Add("onclick",
"DownloadFile_Handle=window.open('URL',
'DownloadFile',
'resizable=no, scrollbars=no, status=no, toolbar=no, height=1, width=1, left=1, top=1 '); DownloadFile_Handle.close(); return true;");
HyperLink_Download.Attributes.Add("onmouseover", "window.status='Click Here to Download File.';return true");
HyperLink_Download.Attributes.Add("onmouseout", "window.status=''; return true;");


DownloadFile_Handle : It is the handle for the opoup so that u can do any action if you want with it.
DownloadFile : this is the target location where the popup will open. if u have any target location like this the popup willopen in that if not it will open in a new window.
the best thing is that even though u clicked the same link more than one time, u wont be getting diffrent popup, the same popup which is opened will reload again and again