如何在edittext上验证IP以完成此操作?

编程入门 行业动态 更新时间:2024-10-28 20:28:10
本文介绍了如何在edittext上验证IP以完成此操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

public void checkIP(String Value) { Pattern pattern = Patternpile("[0-255].[0-255].[0-255].[0-255]"); Matcher matcher = pattern.matcher(Value); boolean IPcheck = matcher.matches(); if(IPcheck){ boolean IsValidData=true; String _strServer=((EditText)findViewById(R.id.txtserver)).getText().toString().trim(); } //it is IP else{ Toast.makeText(getBaseContext(), "Please Check Your IP Format: ", Toast.LENGTH_SHORT).show(); } //it is not IP } public void loginbuttonclick(View v) { ProgressDialog pDialog = new ProgressDialog(LoginActivity.this); // Set progressbar title pDialog.setTitle("Authentication"); // Set progressbar message pDialog.setMessage("Authenticating..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); // Show progressbar pDialog.show(); try { //Validate input data boolean IsValidData=true; String _strServer=((EditText)findViewById(R.id.txtserver)).getText().toString().trim();; //"192.168.0.172"; String _strUser=((EditText)findViewById(R.id.txtuser)).getText().toString().trim();;//"admin"; String _strPass=((EditText)findViewById(R.id.txtpass)).getText().toString();//"admin"; if(_strServer==null || _strServer.isEmpty() || _strServer=="") { IsValidData=false; pDialog.dismiss(); Toast.makeText(getBaseContext(),"Kindly enter valid server ip! : ",Toast.LENGTH_SHORT).show(); }

我尝试过: 对于null和Empty我已经完成了,所以如何放置checkIP?请帮助..

What I have tried: For null and Empty I have done, so How do I put checkIP? please help..

推荐答案

我想说使用这个正则表达式来确保它的格式正确 ([0-9] {1,3} \。){3} [0-9] {1,3} 然后 将它拆分为'。',解析为一个整数并检查它是否在范围(0-255)或不在 I would say use this regular expression to make sure it's in the proper format ([0-9]{1,3}\.){3}[0-9]{1,3} and then split it on '.', parse it to an integer and check to see whether it lies in range (0-255) or not

更多推荐

如何在edittext上验证IP以完成此操作?

本文发布于:2023-07-31 15:35:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1259962.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   如何在   edittext   IP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!