gpt4 book ai didi

javascript - 是的架构 : How to add new line in error message

转载 作者:行者123 更新时间:2023-12-04 12:56:18 26 4
gpt4 key购买 nike

matches(
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/,
`Must contain 8 characters, At least one (1) uppercase, one (1) lowercase, one (1) Number and one special case character`
)
matches(
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/,
`Must contain 8 characters,\n At least one (1) uppercase, one (1) lowercase, one (1) Number\n and one special case character`
)
如何在匹配错误消息上设置新行?
因为我已经尝试过 \n<br/>但它不起作用。
我想做的是这样的:
Must contain 8 characters,
At least one (1) uppercase, one (1) lowercase, one (1) Number
and one special case character
输出应该是这样的^
但在我这边,它将设置新行。
输出是这样的: Must contain 8 characters, At least one (1) uppercase, one (1) lowercase, one (1) Number and one special case character它不会改变任何东西。

最佳答案

设置 white-space: pre-wrap 将使行在换行符或 <br/> 处断开:

.matches(
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/,
`Must contain 8 characters,\n At least one (1) uppercase, one (1) lowercase, one (1) Number\n and one special case character`
),
{errors.firstName && (
<div style={{ color: "red", whiteSpace: "pre-wrap" }}>
{errors.firstName.message}
</div>
)}
现场演示
Edit 66730451/how-to-set-new-line-on-matches

关于javascript - 是的架构 : How to add new line in error message,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66730451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com