{ setemail(例如currentTarget.value) },html,reactjs,asynchronous,use-state,Html,Reactjs,Asynchronous,Use State" /> { setemail(例如currentTarget.value) },html,reactjs,asynchronous,use-state,Html,Reactjs,Asynchronous,Use State" />

Html 删除React上带有正则表达式的最后一个字符 const[email,setemail]=useState(“”); 导出常量lim_num=/[^0-9]/gi; const checkEmail=(e)=>{ 如果(限制数量测试(电子邮件)){ 警报(“숫자만 허용"); 设置电子邮件(如currentTarget); } } 常量EmailHandler=(e)=>{ setemail(例如currentTarget.value) }

Html 删除React上带有正则表达式的最后一个字符 const[email,setemail]=useState(“”); 导出常量lim_num=/[^0-9]/gi; const checkEmail=(e)=>{ 如果(限制数量测试(电子邮件)){ 警报(“숫자만 허용"); 设置电子邮件(如currentTarget); } } 常量EmailHandler=(e)=>{ setemail(例如currentTarget.value) },html,reactjs,asynchronous,use-state,Html,Reactjs,Asynchronous,Use State,我正在用正则表达式删除最后一个字符。 但是,由于电子邮件是以状态管理的,如果使用useState,则不会由于异步处理而将其删除 如何修复它?请注意,checkEmail调用setemail(e.currentTarget)而不是setemail(e.currentTarget.value),如果它存储字符串,这将更合适……我也看不到任何删除最后一个字符的操作,不管是否使用regex。 const [email, setemail] = useState(""); export

我正在用正则表达式删除最后一个字符。 但是,由于电子邮件是以状态管理的,如果使用useState,则不会由于异步处理而将其删除


如何修复它?

请注意,
checkEmail
调用
setemail(e.currentTarget)
而不是
setemail(e.currentTarget.value)
,如果它存储字符串,这将更合适……我也看不到任何删除最后一个字符的操作,不管是否使用regex。
const [email, setemail] = useState("");
export const lim_num = /[^0-9]/gi;

   const checkEmail = (e) => {
      if(lim_num.test(email)) {
        alert("숫자만 허용");
        setemail(e.currentTarget);
      }
   }

    const EmailHandler = (e) => {
      setemail(e.currentTarget.value)
    }

<input type = "email" onChange = {EmailHandler} placeholder = "이메일" onBlur ={checkEmail}/>