如何在android中验证字母表?
如何验证edittext字段,使其在输入时不接受字母,而只接受数字?我已经为空的edittext编写了代码…也就是说,如果edittext中没有输入任何内容,则会发出警报。但是如何使我的edittext只接受数字而不接受字母?如何在android中验证字母表?,android,Android,如何验证edittext字段,使其在输入时不接受字母,而只接受数字?我已经为空的edittext编写了代码…也就是说,如果edittext中没有输入任何内容,则会发出警报。但是如何使我的edittext只接受数字而不接受字母? 关于这一点,请帮助我…非常感谢您…您只需在xml文件中使用输入类型作为数字,如下所示 android:inputType="number" 您只需在xml文件中使用输入类型作为数字,如下所示 android:inputType="number" 将InputType设
关于这一点,请帮助我…非常感谢您…您只需在xml文件中使用输入类型作为数字,如下所示
android:inputType="number"
您只需在xml文件中使用输入类型作为数字,如下所示
android:inputType="number"
将InputType设置为EditField的数字,使其仅接受数字 比如说
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="5dp"
android:inputType="number"
android:singleLine="true" />
将InputType设置为编辑字段的数字,使其仅接受数字 比如说
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="5dp"
android:inputType="number"
android:singleLine="true" />
您可以使用正则表达式
if (!Pattern.matches("^[0-9 ]*$", s))
{
et.setError("Allow only Numerics");
}
或
指定
android:inputType="number"
对于您的xml文件中的编辑文本,您可以使用正则表达式
if (!Pattern.matches("^[0-9 ]*$", s))
{
et.setError("Allow only Numerics");
}
或
指定
android:inputType="number"
对于您的xml文件中的edittext,请在edittext中使用以下内容:
android:hint="@string/phone_no_hint"
android:digits="0123456789"
android:inputType="phone"
在编辑文本中使用此选项:
android:hint="@string/phone_no_hint"
android:digits="0123456789"
android:inputType="phone"
在
EditText
的声明中使用android:inputType=“number”
。这将通过显示数字键盘来禁止输入除数字以外的任何内容。在编辑文本的声明中使用android:inputType=“number”
。这将简单地禁止通过显示数字键盘输入除数字以外的任何内容