Translate

Wednesday, March 5, 2014

JavaScript

Capitalize First Letter of a String:

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

"hello world".capitalize();  =>  "Hello world" 

RegularExp for name validation:

var regex = /^[0-9a-zA-Z]+.{2,9}$/;
if (regex.test(name.value)) {
//Do something.
}


No comments:

Post a Comment