Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^-*\.+$|[^-0-9\.]|^\.+(?!$)|^0+(?=[0-9]+)|\.(?=\.|.+\.)|(?!^)-
/
g

Description

Used for replace characters on keyup in javascript:

		$(document).on("keyup", ".input", function(e) {
			var target = $(e.target);
			var value = target.val();
			target.val(value.replace(/^-*\.+$|[^-0-9\.]|^\.+(?!$)|^0+(?=[0-9]+)|\.(?=\.|.+\.)|(?!^)-/g, ''));
		});
Submitted by anonymous - 7 years ago