Saturday, March 7, 2009

Aptana with cakePHP


Aptana is a pretty good IDE (http://www.aptana.com/) based on Ecplise.

The great thing is that it works with cakePHP.

Just one thing is that cakePHP v1.2 have the views with a ".ctp" extension and Aptana does not handle the code colouring, etc. Luckily this is an easy fix:

Click Window->Preferences...

Select General->Editors->File Associations

Click the "Add.." button and add in *.ctp

*.ctp will appear under "File Types". Click on *.ctp and click the "Add.." button for Associated Editors. Select Aptana PHP Editor.

Done.

Monday, February 23, 2009

Useful Javascript

It's been a while, but I'm doing a bit of javascript again. I have to perform some validation on the user's input and with regular expression it makes the validation much cleaner. The downside is the someone else who comes along and have no idea about regular expression is going to have problem maintaining the code. Oh well.

Validating Email
function validate_email(field) {
var email = document.getElementById(field).value;
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)
}

Validating Mobile Number
function validate_mobile(field) {
var mobile_no = document.getElementById(field).value;
return /^[89][0-9]{7}$/.test(mobile_no);
}

Clean and simple.