Thursday, July 26, 2007

Using regular expressions in JavaScript

Today I learnt to use Regular Expressions in JavaScript. Actually I haven't touched regular expressions from last two years. I used them two years before in Lex & Yacc programming which was solely based on REs.
It's very interesting & useful in JavaScript to make any type of validations like for float value, email address, etc. on the client side.
I tried to develop the RE for validating the float value which contains e/E in it. It was pretty interesting to see the RE coming up part by part. Finally the full fledged RE to validate float value was formed. I would like to share it:

var floatRegExp = /^([+\-])?\d*([\.])?\d*([eE]([+\-])?)?\d*$/;

Your view on the above RE is welcomed :)

2 comments:

Kafka said...

Good deal, had been looking around quite a bit to find this. Thanks!

Unknown said...

Hi , i am not able to implement the javascript validation using regex class.That' y ur code is also french for me .Please can u help me out to use regex and at least the float value validation iam using C#.net web form


_________________________________________________________________________________________________________________

"Look at the sky. We are not alone. The whole Universe is friendly to us and conspires only to give the best to those who dream and work."

- Dr. A P J Abdul Kalam
_________________________________________________________________________________________________________________