Archive for the 'Programming' Category

Trim Last Character(s) from a String in Javascript

Today, I had a need to join comma separated strings in Javascript which turned out to be very easy. I wrote something similar to this
for(var i=0; i < length; i++){
string=string+labels[i]+”,”
}
where string was defined as a var and labels as array.
The difficult part was to remove the last comma. After googling for fifteen minuted, I decided [...]

Create .htaccess file in Vista

I enjoy using command line, especially for things that I cannot do using GUI. Today, I spent good 15 minutes trying to create .htaccess file in c:\xampp\htdocs directory on my Vista machine. I guess Vista expects a file name before the period and therefore kept saying ‘You must type a file name’. This DOS command [...]

Check if Password is Alphanumeric – PHP

A couple of weeks ago, I spent several hours trying to figure out how to check if a password is alphanumeric or not. Following is a function that worked along with explanation.
1 function checkPasswordIsAlphaNumeric($password1){
2 $pattern1 = “/[a-zA-Z]+/”;
3 $pattern2 = “/[0-9]+/”;
4 return ((preg_match($pattern1, $password1)) && (preg_match($pattern2, $password1)));
5 }
Line 1 is simple. We declare a function ‘checkPasswordIsAlphaNumeric’ [...]