Posts

Showing posts from June, 2011

Regular Expression: Support for all languages

Introduction: One of my friend came across a situation where I need to restrict a text control to support only alphabetic. So, we tried with very very simple regular expression; /^[A-Za-z]*$. Now the question arises whether this control also supports any other languages? If I change my setting to French, will this control supports? Solution: The above mentioned regular expression is not generic enough if it wants to match all those characters that are used in languages like French. /^[\p{L}-. ]*$ This says: ^ -: Start of the string [ ... ]* -: Zero or more of the following \p{L} -: Unicode letter characters - -: Dashes . -: Periods -: Spaces $ -: End of the string Keep coding... :-)

Event order in Client-side

If an element and one of its ancestors have an event handler for the same event, which one should fire first?” Not surprisingly, this depends on the browser. The basic problem is very simple. Suppose you have a element inside an element ----------------------------------- | element1 | | ------------------------- | | |element2 | | | ------------------------- | | | ----------------------------------- and both have an onClick event handler. If the user clicks on element2 he causes a click event in both element1 and element2. But which event fires first? Which event handler should be executed first? What, in other words, is the event order? Answers •Netscape said that the event on element1 takes place first. This is called event capturing. •Microsoft maintained that the event on element2 takes precedence. This is called event bubbling. The two event orders are radically opposed. Explorer only supports ev...