L
L
LyoneNET2017-10-01 21:19:56
PHP
LyoneNET, 2017-10-01 21:19:56

How to validate text using regular expressions?

Good evening!
Please tell me how you can compose a regular expression to check the text, according to a given pattern:
number time time time time time
number time time time time time

01 01:00 02:00 03:00 04:00 05:00
02 01:00 02 :00 03:00 04:00 05:00
03 01:00 02:00 03:00 04:00 05:00
04 01:00 02:00 03:00 04:00 05:00
05 01:00 02:00 03:00 04:00 05:00

and if there is at least one extra character in the string, except for spaces, then the check was unsuccessful,
I almost got to the point, but I'm missing something regex101
It is necessary to check the entire string

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2017-10-01
@LioneNET

var str ="01 01:00 02:00 03:00 04:00 05:00 \n02 01:00 02:00 03:00 04:00 05:00\n03 01:00 02:00 03:00 04:00 05:00\n04 01:00 02:00 03:00 04:00 05:00  \n05 01:00 02:00 03:00 04:00 05:00";

if(str.match(/^(\d{1,2}\s+(\d{1,2}\:\d{1,2}\s+){4}\d{1,2}\:\d{1,2}(\s?)+)+$/m)[0] != str)
  console.log("проверка прошла неудачно");
  else
  console.log("проверка прошла удачно")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question