Written on November 04, 2009
by Zaki
and No one have comment
Yes, I have a problem with CodeIgniter built-in Form Validation Library, the lack of direct Regular Expression test/rule is a huge turn off for me especially when I need to use Regular Expression to as a rule to verify user input.
There are alternative with the use of “callback” to by creating an additional method inside your Controller. The solution is good if you have a complex filtering but why bother when all you need to do is a simple RegExp verification. Based on my Twitter status:
[Click here to read more...]
Written on May 30, 2009
by Zaki
and 2 peoples have comment
This is very simple approach to validate date input in DD-MM-YYYY format.
var validate_date = function(date) {
if ( date.match(/^(\d{1,2})\-(\d{1,2})\-(\d{4})$/) ) {
var dd = RegExp.$1;
var mm = RegExp.$2;
var yy = RegExp.$3;
// try to create the same date using Date Object
var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
// invalid day
if ( parseFloat(dd) != dt.getDate() ) { return false; }
// invalid month
if ( parseFloat(mm)-1 != dt.getMonth() ) { return false; }
// invalid year
if ( parseFloat(yy) != dt.getFullYear() ) { return false; }
// everything fine
return true;
} else {
// not even a proper date
return false;
}
};
Written on February 01, 2009
by Zaki
and No one have comment
Savvy.UI version 1.1.3 bring a numbers of new utility function to help you code, among added are Jrun.pickGrep, Jrun.inArrayGrep and Jrun.indexOfGrep. So one would ask, how are these functions can make my life easier? Let me gave you one example;
// this is how things got done in Savvy.UI before 1.1.3
var someFunction = function(method) {
// assign value of method, if method=null then assign GET
var method = Jrun.pick(method, "GET");
// ensure method only POST or GET, default is GET
method = (method.match(/^(get|post)$/i) ? method : "GET");
}
Using Grep you can actually do it this way;
var someFunction = function(method) {
var method = Jrun.pickGrep(method, "GET", /^(get|post)$/i);
}
Written on September 17, 2008
by Zaki
and 10 peoples have comment
Question
Can you share with us the proper Regular Expression (RegExp) for Malaysia’s data format as the following:
- Identification Card
- Postcode
- Phone Number
[Click here to read more...]
Recent Comments