How to construct the regular expression for the case?

2

I need to create an expression for the following case of a code field:

  • Maximum number of characters
  • The first digit should be just numbers [0-9]
  • The code is composed of alphanumeric digits and only the / (bar) and - (hyphen) characters, and they will not always have all of them.

I tried to start one, but without success:

^[0-9][a-zA-Z0-9\/-]+$

Example results

Valid:

260509
8605/05
5ABC605/05
756574-7
88BS-AS0

Invalid:

A8605/05
B756574-7
    
asked by anonymous 23.10.2015 / 19:10

1 answer

3

I believe that this regex serves to capture the desired pattern:

^\d([\w\-/]*)

It means, the first character must be a number, followed by a group that contains a list of characters a-zA-Z0-9 _- /

    
23.10.2015 / 19:16