gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Pattern attribute value \^[а-яА-ЯёЁ\s-]+$\ is not a valid regular expression: Uncaught…
- User
Pattern attribute value ^[а-яА-ЯёЁ\s-]+/v: Invalid character class/ const handleValidationFio = (e)=>{ const element = e.target if(element.validity.valid){ console.log(1) element.setCustomValidity("Только кириллические буквы, дефис и пробелы"); } }
- Assistant
The regular expression pattern
\^[а-яА-ЯёЁ\s-]+$is incorrect.The
^and$symbols are used to indicate the start and end of a string respectively, but they should not be escaped with backslashes.The correct regular expression pattern for matching only Cyrillic letters (uppercase and lowercase), spaces, and hyphens is
^[а-яА-ЯёЁ\s-]+$.Here is the corrected code:
<input onInput={handleValidationFio} pattern="^[а-яА-ЯёЁ\s-]+$" name="fio" type="text" className="form-control" id="fio" required /> const handleValidationFio = (e) => { const element = e.target; if (element.validity.valid) { console.log(1); element.setCustomValidity("Только кириллические буквы, дефис и пробелы"); } }