1.

Solve : regExp correct method?

Answer»

Hello guys

I NEED to make a regExp on a field for percent marks and wrote this one

Code: [Select]<script type="text/javascript">
var marksPattern = /(\d{2}.\d{2}%)/;
</script>

I am using test() method to check user entry, but the problem is that the test() return true event if there was another thing with marks

examples:

1. marksPattern.test('80.67%'); true   

2. marksPattern.test('bla bla 80.67%'); true 

in the second CASE I want it to return false, what is the correct method? This may help:

Code: [Select]^(\d{2})\.(\d{2})%

My JavaScript is a bit rusty, so I'm not sure what those FORWARD slashes in your test pattern represent.

Good luck.

Special thanks to RegExBuilder  Thanks a lot Sidewinder

those forward slashes another way to define a NEW regExp in JS

var rExp = /pattern/flags;

or

var rExp = new RegExp("pattern"[, "flags"]) ;



Discussion

No Comment Found