Community Patterns

Community Library Entry

0

Regular Expression
Created·2017-11-23 11:14
Flavor·ECMAScript (JavaScript)

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

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