java - 在android studio中编辑年龄文本中的验证
问题描述
你好我希望你们都做得很好
我有验证问题我尝试了很多方法,但没有一个有效
我有编辑文本我想放置验证,只允许输入 1 到 15 的数字,但它不起作用请提供任何帮助
String pet_name=petname.getText().toString();
String pet_type=ptype.getText().toString();
String pet_age=page.getText().toString();
String pet_gender=pgender.getText().toString();
String pet_location=plocation.getText().toString();
String pet_des=pdes.getText().toString();
String pet_img=petimg.getText().toString();
int inputInt = Integer.parseInt(page.getText().toString());
if(pet_name.equals(""))
petname.setError("User name Should not be empty");
else if(!pet_name.matches(namevalid))
petname.setError("Should be Only letters");
else if(pet_type.equals(""))
ptype.setError("Should not be empty");
else if(!pet_type.startsWith("Cat")&& !pet_type.startsWith("Dog"))
ptype.setError("Should be Only Cat or Dog");
else if(pet_age.equals(""))
page.setError("Should not be empty");
else if (inputInt <= 15 && inputInt >= 1 ) ;
page.setError("Should be be between 1 to 15 year");
当我添加此代码程序停止工作时,问题就在这里
else if (inputInt <= 15 && inputInt >= 1 ) ;
page.setError("Should be be between 1 to 15 year");
enter code here
解决方案
我固定 thx 给所有人
当我添加年龄代码时,年龄下的其他验证停止工作,所以我将所有代码放入年龄验证中,现在它可以工作了
else if(!page.getText().toString().isEmpty()) {
//check to see if the entered donation is superior to 5 if so go to make payment page
int inputInt = Integer.parseInt(page.getText().toString());
if (inputInt <= 10 && inputInt >= 1) {
if(pet_gender.equals(""))
pgender.setError("Should not be empty");
else if(!pet_gender.startsWith("Male")&& !pet_gender.startsWith("Female"))
pgender.setError("Should be Only Male or Female");
else if(pet_location.equals(""))
plocation.setError("Should not be empty");
else if(pet_des.equals(""))
pdes.setError("Should not be empty");
else if(pet_img.equals(""))
petimg.setError("Should not be empty");
推荐阅读
- python-3.x - 如何在 python 中将 datetime.datetime(2020, 3, 5, 18, 55, tzinfo=tzoffset(None, 19800)) 转换为 2019-01-08 11:49:00.000000?
- ios - 在多个视图控制器中使用相同的表格视图单元
- matlab - 如何在 Simulink 中翻转时间序列数据?
- java - Spring Data JPA 命名存储过程 REF CURSOR 不适用于 SOAP Web 服务
- cordova - Svelte 应用程序无法在 android 版本 6.0.1 或更高版本上运行
- asp.net-mvc - ManagePipelineHandler 模块下的 TTFB / 服务器响应时间慢
- javascript - Laravel 动态表单输入文本和上传文件
- reactjs - 反应光滑的滑块将类组件转换为功能组件
- linux - 解析错误:第 1 行第 8 列的数字文字无效
- java - 尝试为 java 中的游戏制作“再玩一次”功能