regex - Regular Expression to validate my input -


this question has answer here:

i need regular expression validate input. allowed phrases these:

63 0 3-203 1923-2930 

so it's:

  • any number, or
  • any number - number

you can use following regex

^\d+(-\d+)?$ 

demo

explanation

  1. ^: start with
  2. \d+: matches 1 or more numbers
  3. ()?: matches 0 or 1 group
  4. -\d+: matches 1 or more numbers followed -
  5. $: ends with

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -