Hi
I suspected that I made a mistake in regular expressions. Now I have studied a little more and taken into account your comments, and it seems to have become clearer, in any case, at a basic level, understanding has already appeared.
Here is my corrected task-2 code: https://jsfiddle.net/EiNzp/zpjy9aqh/3/
Regexes are a powerful yet complicate concept. I hope you didnāt get frustrated
Iām sure youāre glad to hear that thereās only one tricky little mistake left. I have also two simplifications:
Thereās a special character for āone or moreā: {1,}+
The dot inside character classes (square brackets) loses its special meaning and can be written without backslash. (In my last post I missed that, too )
You will probably be surprised that the following phone number will work: 111(111&1111 . Can you find out why this is the case?
Hint for the phone mistake
Have a look at the ASCII table from 32 to 46.
Solution for the phone mistake
If we want to match a hyphen (`-`) in a character class, it has to be the first or last character. Otherwise it indicates a range. `[ -.]` means "all characters between space and dot". In ASCII these are all characters from 32 to 46. Correct character classes: [ .-] or [-. ]
Regarding the special character āone or moreā:
Thank you for drawing my attention to it, for some reason I didnāt pay attention to it when viewing special characters, itās really easier with it and the code looks simpler.
About my mistake with the phone:
Iām even glad that I allowed it, since I could accidentally do the right thing and not pay attention to the fact that I could be wrong here.
As soon as I looked at your remark and at my code, I immediately guessed what the problem was and after looking at your hint I was convinced of this.
Initially, I thought that this could be solved with a backslash before the hyphen [ \-.].
Then I took a look at your solution and applied it. My version is probably also working, but more complicated. And if there are a lot of such places in the code, it will add a lot of extra characters to the code.
Here is my code after fix: https://jsfiddle.net/EiNzp/x60anm5L/2/
P.S.
Once again I want to thank you for your help, it is priceless.
Youāre right about [ \-.] also working. The backslash always removes the special meaning of the character. I havenāt thought about that, but I agree putting the hyphen at the end looks cleaner.