Menu
Topics Index
...
`

Validate The Name


If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to validate the given name.

Input (String) Output
KiranKumarReddy true
Sonia true
SharukKhan? false
12MaheshBabu false
Prabhas234 false
ViratKohli_!@# false
"" (EMPTY STRING) false
null false



class ValidName
{
    public static void main(String s[])
    {
        String name = "Prabhas";
        boolean result = isValidName(name);
        System.out.println("The given name "+name+" is valid : "+result);

    }


        public static boolean isValidName(String name)
        {
            boolean result = false;
            return result;
        }

}
Topic: StringBuffer getChars() Method In Java With Example

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

we havr to validate a given name... acc to th questn a name is valid only if it contains alphabets upper or lower othrwuse it is invalid.... for this we hv to traverse each chrctr of name and chek if they r alphabts if yes then print true else prnt false..... so to traverse each charactr we need to take a loop and traverse using charAt() .....take loop a=0 to length(name) .......if(name.charAt(a) is between a-z or A-Z) then continue otherwise return false.....so as it will detect any special charactr othr dan alphabets the prgrm will retrn false.... othrwise will continue to next iteration... exit loop... returm true.... if all the cgaractrs r alphabets den prgrm will return true at the end

Posted by Asma Mujtaba Khan    2014-12-25 07:34:32


For validating a given name first we need to check the String should not be null and empty.. Then we have to parse every character in the string and have to check whether it is a letter or not (irrespective of upper or lower).. If any of the character in string is not a letter then isValidName() method should return false otherwise true... For checking the character is a letter or not, we can use Character.isLetter() method or you can use ascii values...

Posted by Gopinath Manchikanti    2014-12-25 08:53:56


Valid name is one if it follows the following:-

1.It should contain and start with only alphabets.
2.It should not start with or contain digit or special symbol.
3.It should not be empty or null.

PROGRAM EXPLANATION:

To check for above rules one Loop is used which will run till lenght of given String and for each character we check if it is number or special symbol we "BREAK" the loop and print "FALSE".

PROGRAM:
if(name=="" || name==null)
result=false;
else{
for(int i=0;i<name.length();i++)
{
    if(Character.isDigit(name.charAt(i)) )
    {
        result=false;
        break;
    }
    else if( Character.isLetter(name.charAt(i)) )
    {
        result=true;
    }
    else
    {
        result=false;
        break;
    }
}
}

Posted by Mânïshå Mùlchåndânï    2014-12-25 10:06:54


Rules:
*Name Must contains only Letter(a-z A-z)
Coding:

* String should not be Empty and Null..if it is return false (if(input==null||input.length==0) return false
*we need to check every char..we must travel through out the String take for loop for travelling

*than check if it is char than result=true else return false
* Character.isLetter(name.charAt(index)) we can check using this method
*after coming out of the Loop return result

Posted by Uday Kumar    2014-12-26 04:24:07


Mânïshå Mùlchåndânï  Don't write the direct code,only explanation will write

Posted by Merit Campus    2014-12-26 04:33:10


This dose is now closed and the winners are Gopinath Manchikanti,  for 'First Correct Comment', Uday Kumar,  for 'Second Correct Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-26 04:38:48


steps:

1st char from the givn string should be uppercase letter.

all the remaining should not contains any number or symbols.

check above 2 condition using if case then you will get correct answer.

check 1st char ---
if(string.charAt(0) lies within upper case alphabet boundry)
if it returns true thn proceed othr if case to check givn string has any numbers or symbols,
here if any number ,symbols present thn break the execution and print false.

for checking each char from the given string use any looping concept for iteration

if false thn print false

Posted by Maheshwari Natarajan    2014-12-26 04:40:01


© meritcampus 2019

All Rights Reserved.

Open In App