Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用方法参数的Java验证_Java_Validation - Fatal编程技术网

使用方法参数的Java验证

使用方法参数的Java验证,java,validation,Java,Validation,我正在尝试使用验证方法验证Signin()和Signup()的用户名和密码字段。现在,当我输入正确的用户名时,它会不断显示错误,我不知道为什么 验证方法: void signup_username_validation(String username) //Username validation for signup { String user_name = ""; if(user_name.length() < 6 || user_name.length() >

我正在尝试使用验证方法验证Signin()和Signup()的用户名和密码字段。现在,当我输入正确的用户名时,它会不断显示错误,我不知道为什么

验证方法:

void signup_username_validation(String username) //Username validation for signup
{
    String user_name = ""; 
    if(user_name.length() < 6 || user_name.length() > 15)
    {
        System.out.println("Username cannot be less then 6 and greater then 15 characters");
        Signup();

    }

}

void signup_password_validation(String password) //Password validation for signup
{
    String pass = ""; 

    if(pass.length() < 6)
    {
        System.out.println("Password cannot be less then 6 characters");
        Signup();
    }

}

您正在分配给
String user_name=”“
并检查此始终为空的值

即检查新创建变量的有效性,您已将其初始化为空字符串。您真正想做的是检查方法参数的有效性

void signup_username_validation(String username) //Username validation for signup
    {
    if(username.length() < 6 || username.length() > 15)
        {
        System.out.println("Username cannot be less then 6 and greater then 15 characters");
        Signup();
        }
    }

void signup_password_validation(String password) //Password validation for signup
    {
    if(password.length() < 6)
        {
        System.out.println("Password cannot be less then 6 characters");
        Signup();
        }
    }
void signup\u username\u验证(字符串username)//注册的用户名验证
{
if(username.length()<6 | | username.length()>15)
{
System.out.println(“用户名不能少于6个字符,不能超过15个字符”);
注册();
}
}
无效注册\密码\验证(字符串密码)//注册的密码验证
{
if(password.length()<6)
{
System.out.println(“密码不能少于6个字符”);
注册();
}
}
试试看

公共类测试{
无效注册\用户名\验证(字符串用户名)//注册的用户名验证
{
//字符串user_name=“”;
if(user_name.length()<6|user_name.length()>15)
{
System.out.println(“用户名不能少于6个字符,不能超过15个字符”);
注册();
}
}
私人无效注册(){
//TODO自动生成的方法存根
}
无效注册\密码\验证(字符串传递)//注册的密码验证
{
//字符串pass=“”;
if(pass.length()<6)
{
System.out.println(“密码不能少于6个字符”);
注册();
}
}
}

他对密码做了同样的操作。它要求初始化。那么我应该如何初始化变量user_name?使用username param variable而不是创建新的user_name(同时检查null)@Jeff Craine您传入了
username
变量,但从未使用过它。然后您创建了另一个
user\u name
变量并使用了该变量而不是
键盘.next()如果您希望用户在完成键入时按enter键。
void signup_username_validation(String username) //Username validation for signup
    {
    if(username.length() < 6 || username.length() > 15)
        {
        System.out.println("Username cannot be less then 6 and greater then 15 characters");
        Signup();
        }
    }

void signup_password_validation(String password) //Password validation for signup
    {
    if(password.length() < 6)
        {
        System.out.println("Password cannot be less then 6 characters");
        Signup();
        }
    }
    public class Test {

        void signup_username_validation(String user_name) //Username validation for signup
        {
//          String user_name = ""; 
            if(user_name.length() < 6 || user_name.length() > 15)
            {
                System.out.println("Username cannot be less then 6 and greater then 15 characters");
                Signup();

            }

        }

        private void Signup() {
            // TODO Auto-generated method stub

        }

        void signup_password_validation(String pass) //Password validation for signup
        {
//          String pass = ""; 

            if(pass.length() < 6)
            {
                System.out.println("Password cannot be less then 6 characters");
                Signup();
            }

        }

    }