Skip to content

Instantly share code, notes, and snippets.

@gthrm
Last active September 22, 2019 07:09
Show Gist options
  • Save gthrm/44a7ce708001c8282ce050daf4a42e6f to your computer and use it in GitHub Desktop.
Save gthrm/44a7ce708001c8282ce050daf4a42e6f to your computer and use it in GitHub Desktop.
RegExp + switch JS
switch (digitsOnly) {
case digitsOnly.match(/\s+/g) ? digitsOnly : true:
result = digitsOnly.replace(/\s+/g, '');/* оставляем только цифры, удаляем пробелы*/
break;
case digitsOnly.match(/\.+/g) ? digitsOnly: true:
result = digitsOnly.replace(/\.+/g, '');/* оставляем только цифры, удаляем точки*/
break;
case digitsOnly.match(/^\d+/g) ? digitsOnly: true:
result = digitsOnly.replace(/\s+/g, '');/* оставляем только цифры, удаляем пробелы*/
break;
default:
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment