Comments (6)
ok cool. yeah the URL spec is nasty but since node has URL
available globally, I think we can get by with try { new URL(value); } catch (e) { return false }
on the server. If folks are running in non-node environments, they'll need URL available which should be fine for most alternative server-worker-API based environments.
Thanks for the references!
from remix-validity-state.
Yeah this is currently a "by design" case since I'm not sure what exactly the browsers are all doing internally for their type
validations. Client-side we just let the browser tell us when an input is valid. Server-side we have to re-implement the same checks (see builtInValidations
in the library code). Things like required
and minLength
are simple to re-implement, but I've not yet bothered with the type
validations.
I'm definitely not interested in some nasty regex to try to validate email addresses. Mostly because they're horrible to debug and generally gives tons of false negatives. I'd definitely also recommend giving this post a read - this changed how I thought about email addresses significantly many years ago.
I think I could be convinced to do something very simple on the server such as /.+@.+/
to make sure there's something before and after an @
character but I doubt I'd want to go any further. I'll also need to look into what that would mean for the rest of the inputs (type url, tel, date, etc.) since if I do one I'd prefer to do them all and unsure at the moment if that opens up a can of worms.
For now, I'd recommend doing your own simple regex-based check. In the end though, the proper way to validate an email address on the server is to send it an email with a verification link :)
from remix-validity-state.
Here's the standard browsers adhere to along with a fairly non-convoluted regex that satisfies it and doesn't overly restrict: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address. I think if using type=email prevents international emails addresses, then it's okay to do so on the server too and the user can override if they please
from remix-validity-state.
Oh cool I didn't know the spec gave their own regex, that's handy. I'll do some digging on the rest of the types as well. I hope (but doubt) they'll all be so easy
from remix-validity-state.
Oh I thought this was already being done in a previous version.
There are only two type
's that have intrinsic validation: email
and URL
.
I couldn't find the regex/validation code for a URL, but here's the spec.
from remix-validity-state.
Released in 0.10.0
from remix-validity-state.
Related Issues (20)
- Support checkbox/radio/textarea/select HOT 3
- Incorrect input value during async validation
- Date range validation HOT 7
- Server-only custom validation HOT 3
- Better Typescript Types on serverFormInfo.submittedValues HOT 6
- Better Typescript validation on errorMessages
- Expose form-level `valid` prop on client side for submission prevention?
- Error in validateInput useEffect Error: validateInput expected an inputEl.form to be available for input HOT 6
- Type mismatch on React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement> HOT 1
- Consider allowing controlled inputs—example of problem with HeadlessUI Listbox HOT 1
- Better TypeScript types on validation attributes HOT 7
- Better handling of checkbox edge cases HOT 2
- Allow conditionally rendered optional inputs HOT 1
- Feature Request: Form checkValidity method HOT 1
- Add support for min/max strings on date input HOT 2
- Validation handling HOT 1
- Fix select type HOT 3
- Question: should whole component re-render on checkbox onChange? HOT 1
- Bug updating state of select element HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remix-validity-state.