CSS Style center

CSS Styles, CSS tips

Portfolio

Javascript prototype extension method

Lets say you have some string that you want to preform some action on him, like check if the string is Hebrew, to know if you want to display it as rtl text or ltr…

first we will need to have that string in some integer like this:

var string = "some string for check";

then we will need a String.prototype function ready to read that string and return us a value. It will be like this:

String.prototype.isHebrew = function () {
	return (this.match(/[\u0591-\u05F4]/) != null);
};

this function will get that string when called check if it contains Hebrew characters with regex and return us a true or false value. so what is left for us to do is just call it in the following way:

string.isHebrew();

and here you go, you can check every string like that if it contains Hebrew characters or no.

Good luck :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>