【发布时间】:2020-10-23 05:19:39
【问题描述】:
我必须建立一个 NodeJS/React 网站。该网站是关于用户发布他们的活动的。因此,当用户添加他的活动时,他可以选择添加活动的注册链接(链接到他们可以直接申请的第三方网站)。添加注册链接只需输入字段即可。 我在哪里要求链接:
const AddEvent = () => {
return <input type="text" name="registrationLink" />;
};
我在哪里显示链接:
const EventInfo = props => {
const { registrationLink } = props; // i.e this outputs https://www.google.com
return <a href={registrationLink}>Register Now</a>;
};
我现在如何验证输入以仅接受链接(即仅使用 https 的链接)?有什么简单的方法可以做到这一点?最好的!
【问题讨论】:
-
试试
<input type="url" name="registrationLink" pattern="https?://.+" required />
标签: javascript html reactjs