Using RegEx(Regular Expressions) in JavaScript


Javascript has built-in support for regular expression in almost all browsers. This means you can use regular expression at client side too. You can use to validate the user’s input data at client side itself to reduce the server side processing, however you may want to check those at server side too for security problems.…

Format Number in Currency using javascript


Now you can convert your number in currency format using the below function. function formatNumber(number) { number=number+”; return number.replace(/[^d.-]/g,”).replace(/(.d{2})[Ww]+/g, ‘$1’).split(”).reverse().join(”).replace(/(d{3})/g, ‘$1,’). split(”).reverse().join(”).replace(/^([-]{0,1}),/, ‘$1’). replace(/(.d)$/, ‘$1’+’0’).replace(/.$/, ‘.00’); }

Get URL Parameters Using Javascript


<script> function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split(“&”); for (var i=0;i<vars.length;i++) { var pair = vars[i].split(“=”); if (pair[0] == variable) { return pair[1]; } } alert(‘Query Variable ‘ + variable + ‘ not found’); } </script> Now make a request to page.html?x=Hello <script> alert( getQueryVariable(“x”) ); </script>