Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I make regex pattern with characters, numbers, white space, double quotes, ?, !, commas, hyphen, dots, @ and &

How can I make regex pattern allowing following characters, numbers, white space, double quotes, ?, !, commas, hyphen, dots, @ and &

                  <textarea
                    id="comments"
                    type="textarea"
                    placeholder='comments'
                    {...register("comments", {
                        required: true,
                        minLength: {
                            value: 5,
                            message: "Minimum length of 5 letters"
                        },
                        pattern: {
                            value: /^[a-z0-9]+$/i,
                            message: "Supports characters, numbers, white space, "", ?, !, @, & and commas"
                        }
                    })}
                    >
                  </textarea>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Change

value: /^[a-z0-9]+$/i,

to

value: /^[a-z0-9\s"?!,\-.@&]+$/i,

\s is whitespace, and - needs to be escaped so it’s not treated as the range separator. The rest is just the other characters you said you want to allow.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading