Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

validating textbox with regex

Here is my fiddle
https://jsfiddle.net/r2d22k18/7gc5pwaj/2/

I'm trying to prevent typing of this </ or />

In the above fiddle when i type </ or />  the second character is deleted

Instead of deleting the second character , how do I just put a space in between.

So if I type this </ it will put a space in between and show this < /
So if I type this /> it will put a space in between and show this / >
Avatar of leakim971
leakim971
Flag of Guadeloupe image

replace :
                if (theRegExp.test(theTextBoxValue)) {
                    $(this).val(window.saveTheValueForCheckingInKeyUp);
                }

Open in new window

by :
                if (theRegExp.test(theTextBoxValue)) {
                    var v = window.saveTheValueForCheckingInKeyUp.replace(/<\//g, "< /");
                    v = v.replace(/\/>/g, "/ >");
                    $(this).val(v);
                }

Open in new window

Avatar of maqskywalker
maqskywalker

ASKER

leakim971,

here is the updated fiddle, i replaced the if statement with what you said
https://jsfiddle.net/r2d22k18/wx0uv6ev/1/

But space is not being inserted. Do I have a mistake?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice! Genius! Thanks!