Javascript React Js输入类型=";“数字”;不在firefox中工作

Javascript React Js输入类型=";“数字”;不在firefox中工作,javascript,reactjs,validation,Javascript,Reactjs,Validation,在上面的代码中,Chrome浏览器仍然运行良好,而firefox不支持type=“number” 输入字段允许所有类型的文本关键字。我的代码中有什么错误 尝试改变你的模式 <Form.Input type="number" pattern="[1-9]" disabled={renderDisableInput( this.state.user.role )} placeholder="Phone" required={tru

在上面的代码中,Chrome浏览器仍然运行良好,而firefox不支持
type=“number”


输入字段允许所有类型的文本关键字。我的代码中有什么错误

尝试改变你的模式

<Form.Input
    type="number"
    pattern="[1-9]"
    disabled={renderDisableInput(
        this.state.user.role
    )}
    placeholder="Phone"
    required={true}
    value={this.state.phone}
    onChange={this.handleChange}
    name="phone"
/>

在下面的示例中,您可以阻止字符

                          <Form.Input
                            type="number"
                            pattern="/[0-9]+/"
                            disabled={renderDisableInput(
                              this.state.user.role
                            )}
                            placeholder="Phone"
                            required={true}
                            value={this.state.phone}
                            onChange={this.handleChange}
                            name="phone"
                          />
从“lodash”导入{includes};
常量字母=[
‘a’、‘b’、‘c’、‘d’、‘f’、‘g’、‘h’、‘i’、‘j’、‘k’、‘l’、‘m’、‘n’、‘o’、‘p’、‘q’、‘r’、‘s’、‘t’,
‘u’、‘v’、‘w’、‘x’、‘y’、‘z’、‘A’、‘B’、‘C’、‘D’、‘F’、‘G’、‘H’、‘I’、‘J’,
‘K’、‘L’、‘M’、‘N’、‘O’、‘P’、‘Q’、‘R’、‘S’、‘T’、‘U’、‘V’、‘W’、‘X’、‘Y’、‘Z’,
];
返回(
{
if(包括(字母表,e.键)){
e、 预防默认值();
} 
}}
/>
)

Firefox确实支持。有什么东西被渲染了,或者你的控制台有错误吗?很难说自版本23以来Firefox支持了什么。仍然允许阿尔法数值
import { includes } from 'lodash';
const alphabets = [
'a','b','c','d','f','g','h','i','j','k','l', 'm','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D', 'F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
];

    return (
        <input
        type="number"
        value={value}
        onKeyDown={(e) => {
          if (includes(alphabets, e.key)) {
            e.preventDefault();
          } 
        }}
      />
)