Answer the question
In order to leave comments, you need to log in
How to validate such a hash tag?
There is such a function for validating a field with hash tags - https://codepen.io/viktoraz/pen/KKmqLKK?editors=1010
Hash tags must be separated by a space and each must match the pattern.
1 problem is that the regular expression does not check every hash tag, that is, it allows you to enter the first hash tag without a grid, if the last one is with a grid.
2 problem is to clear the field. If you enter any characters, and then clear the field, the field will still not be valid, although it is empty (checked)
I assume that the problem is just in the regular expression, but I tried many different ones, nothing fits. Is there another way to validate hash tags?
Answer the question
In order to leave comments, you need to log in
Alternatively, you could make a slightly more powerful regular expression that allows 1 or more valid hashtags separated by spaces. Very rude - add \s* to the end of your regular expression (before the end of the line) and wrap the whole thing in ()+.
For example, regex: (#(?<tag>[A-Za-zА-Яа-я]{1,19})\s*)+
( https://regex101.com/r/rfH4AA/1 )
Then we get all the values of the tag group, I'm not strong in js, but I think there must be a way.
I don't understand what the problem is
if("ПОЛЕ ПУСТОЕ"){
//Не проверяете регуляркой
//Отправляете на сервак
}
Hash tags must be space separated
let input = "#adsasddasd #adsasdasda #gadsqw-asdas"
let arrHashTag = input.split(" ");
pattern matching
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question