using regular expression with javascript

Hi experts,

I have this example fiddle
https://jsfiddle.net/r2d22k18/oyhg1je0/1/

In this example I prevent users from typing the symbol > in a textbox.

How do i do the same thing, but using a regular expression?
LVL 1
maqskywalkerAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
Try this :
	$('#TextBox1').on("keydown", function (e) {
		window.saveTheValueForCheckingInKeyUp = $(this).val();
	});

	$('#TextBox1').on("keyup", function (e) {
		var theTextBoxValue = $(this).val();
		var theRegExp = /someRegularExpressionHere/;
		if ( theRegExp.test ( theTextBoxValue ) ) {
				$(this).val( window.saveTheValueForCheckingInKeyUp ); 
		}
	});

Open in new window

0
 
leakim971PluritechnicianCommented:
let's say the key down don't put the corresponding key in the textbox
when you want to check the textbox WITH the value inside
so this code is not applicable
0
 
maqskywalkerAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.