HOME > System software > Regex: Only Numbers - How To Get Only Numbers

Regex: Only Numbers - how to get only numbers

If you want to check an input or a string for a certain pattern, the use of regular expressions is a good way. This way you can replace or sort out certain characters. If you only want to accept strings that consist of numbers only, then that is also possible.

This is how you check your regex for "Only Numbers"

With regex you can check input for certain criteria. However, for this it is necessary to follow the appropriate syntax. For example, it is possible to test a string to see if it consists of only a certain type of character or begins or ends with a special character. If you want to know if a text consists only of numbers, then this is easily possible with a regex.
  1. First you need the flag that all numbers are allowed. You achieve this with the expression [0-9].
  2. Next, you still need to mark that all elements of your string should consist only of numbers. To do this, you must specify that it should begin and end with a number. Hierfür benötigen Sie die Zeichen „^“ und „$“.
  3. Damit auch Strings erkannt werden, die aus mehreren Zahlen bestehen, müssen Sie Ihrem regulären Ausdruck ein „*“-Zeichen hinzufügen.
  4. Abschließend sollte Ihr Regex wie folgt aussehen: „^[0-9]*$“.
  5. Über spezielle Webseiten ist es zudem möglich, Ihre Regex nochmal zu überprüfen.

By Luiza

Tinder Plus: Costs and features at a glance :: BahnBonus: How to collect points - and how to redeem them
USEFUL LINKS