Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14713 closed bug (duplicate)

possible regex/keyup bug with Chrome?

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


I have encountered a regex problem when using jQuery's latest minified version with Chrome version 32.

The code I have (see below) is restricting the user's input to a numbers from -99 to 99, with a keyup event-listener.

In Chrome, try starting the input with "--" or maybe "1-" and the input restriction breaks (then allowing the user to type whatever, even letters, length unrestricted). Note that no error is occurring in either Firefox 26 or IE 11.

Upon running the code in Chrome, this error is output to the console:

event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery-latest.js:5374

Here is the code:

<!DOCTYPE html>
		<title>Regex Testing</title>
		<style type="text/css">
			div {
				background-color: gray;
				text-align: center;
				margin-left: auto;
				margin-right: auto;
				width: 500px;
				height: 100px;
				display: table;
				p {
					background-color: white;
				p, input {
					display: table-cell;
					vertical-align: middle;
			<p>Enter a 2 digit number, positive or negative:<p>
			<input type="number" id="answer" placeholder="enter a number..." />
		<!-- jQuery imported here: -->
		<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
		<script type="text/javascript">
			// NOTE: only keyup can determine the CURRENT number of characters in an input field:
			$("#answer").keyup(function () {
				// allowing numbers and dashes only:
				var data = $(this).val();
				var regx = "^\-?[1-9]{0,1}[0-9]{0,1}$";

				if (data == "" || data.match(regx)) {
				} else {
					$("#answer").val(data.substr(0, data.length - 1));

Thanks for an awesome product though, I love jQuery!

Change History (1)

comment:1 Changed 9 years ago by timmywil

Resolution: duplicate
Status: newclosed

Duplicate of #14282.

Note: See TracTickets for help on using tickets.