-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🛠️ FIX : First Name Field validation in Contact us page #2333
Conversation
WalkthroughThe changes in Changes
Assessment against linked issues
Possibly related issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@akash70629 is attempting to deploy a commit to the Vivek Prajapati's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<input type="text" id="fname" className="w-full p-2 border rounded" placeholder="Enter your first name" minLength={3} required pattern="[a-zA-Z ]+" | ||
onInvalid={(e) => { | ||
e.target.setCustomValidity('Numbers and Symbols are not allowed.'); | ||
}} | ||
onInput={(e) => { | ||
e.target.setCustomValidity(''); | ||
}}/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Expand input validation to accommodate international names
The current pattern pattern="[a-zA-Z ]+"
restricts input to English letters and spaces. This might exclude valid characters in international names, such as accented letters (e.g., é, ñ), hyphens, or apostrophes.
Consider updating the validation logic to allow for a wider range of characters common in international names.
One approach is to remove the pattern
attribute and perform validation using a Unicode-aware regular expression in the onInput
event handler:
<input
type="text"
id="fname"
className="w-full p-2 border rounded"
placeholder="Enter your first name"
minLength={3}
required
onInput={(e) => {
const value = e.target.value;
const regex = /^[\p{L} \-'’]+$/u;
if (!regex.test(value)) {
e.target.setCustomValidity('Please use letters only.');
} else {
e.target.setCustomValidity('');
}
}}
/>
- The
\p{L}
pattern matches any kind of letter from any language when using the Unicode flagu
. - The regex allows spaces, hyphens
-
, and apostrophes'
or’
, accommodating names like "O’Connor" or "Anne-Marie". - Ensure that the JavaScript environment and targeted browsers support Unicode regex patterns with the
u
flag.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Congratulations, Your pull request has been successfully merged 🥳🎉 Thank you for your contribution to the project 🚀 Keep Contributing!! ✨ |
Changes proposed
The "First Name" field on the Contact us page only accepts alphabetical letters (a-z, A-Z). Currently, the field does not allow users to input symbols and special characters, which may lead to invalid or spam submissions.
Fixes Issue
Closes #2331
Screenshots
Before
After
Checklist
Summary by CodeRabbit
New Features
Bug Fixes
User Experience Improvements