Skip to main content

Posts

Showing posts with the label Java Script

validate email and phone number with Regular Expressions

Here is sample to validate Phone, Email, URL http://www.costudio.com/contactus.asp emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2} (comnetorgeduintmilgovarpabizaeronamecoopinfopromuseum))$/ phoneRe = /^((\+\d{1,3}(- )?\(?\d\)?(- )?\d{1,5})(\(?\d{2,6}\)?))(- )?(\d{3,4}) (-)?(\d{4})(( x ext)\d{1,5}){0,1}$/ http://javascript.about.com/library/blre.htm Jquery Validation http://bassistance.de/jquery-plugins/jquery-plugin-validation/

js not working in firefox

in IE, document.all is working but not in firefox, in firefox have to use document.getElementById instead IE: document.all.tab1Div.style.display='none'; document.all.tab2Div.style.display=''; document.all.tab3Div.style.display='none'; document.all.li1Div.className = ''; document.all.li2Div.className = "selected"; document.all.li3Div.className = ''; Firefox: document.getElementById('tab1Div').style.display='none'; document.getElementById('tab2Div').style.display=''; document.getElementById('tab3Div').style.display='none'; document.getElementById('li1Div').className = ""; document.getElementById('li2Div').className = 'selected'; document.getElementById('li3Div').className = '';

javascript limitation on array (Max Javascript Array)

The problem is not the number of array elements but the number of statements within a function. If a javascript function in IE7contains more than 32768 statements it generates this 'syntax error'. Now a javascript function contains rarely more than 250 statements unless you are filling a big array with assigment statements of course . A workaround for this is using multiple functions. Also it seems if you make multiple blocks (using { } ) within a function where each block contains less than 32768 statements the error also disappears. So the real cause of the problem in IE7 seems to be that they are using a short integer to count the number of statements within a block.

Using the enter key to submit a form

<input name="LoginPass" type="password" id="LoginPass" onkeydown="if ((event.which && event.which == 13) (event.keyCode && event.keyCode == 13)) { DoSubmit(1); return false; } else return true;" />

Regular expressions in JavaScript

JavaScript includes full support for Perl-style regular expressions, and it's extremely useful for string matching processes. Coding a script to check sensitive user data is sometimes pretty straightforward. But most of the time this process is not so easy. With current websites, we'll need to check the proper standardized format of an email address or a URL. That would be a nightmare for programmers, not to mention a confusing and inefficient error-prone process for checking data validity. A regular expression is a way of describing a pattern in a piece of text. In fact, it's an easy way of matching a string to a pattern. We could write a simple regular expression and use it to check, quickly, whether or not any given string is a properly formatted user input. Here are a few special characters that can be used for matching characters in regular expressions: \n // a newline character . // any character except a newline \r // a carriage return character \t // a tab character...