execption handling

execption handling

I have the following form(as example).

Name:_____ Id number:____

I want to handle that as if one enter numbers in place of name,my program says please enter only character place of the name.

How I should do????????

Dame Leta

From Ethiopia,Jimma University, Department of Computer Science.

View Answers

March 20, 2012 at 5:42 PM

import java.util.*;
import java.util.regex.*;

class RegularExpressions {

        public static boolean validateName(String name) {
                return name.matches("\\p{Upper}(\\p{Lower}+\\s?)");
        }

        public static boolean isNumeric(String str){
         return str.matches("-?\\d+(.\\d+)?");
}


        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                System.out.print("Enter Name: ");
                String name = input.nextLine();
                while (validateName(name) != true) {
                        System.out.print("Invalid Name(Name and Surname shoulb be started with capitals with space between name and surname)!");
                        System.out.println();
                        System.out.print("Re-Enter Name: ");
                        name = input.nextLine();
                }
                System.out.print("Enter ID: ");
                String  id = input.next();
                while(isNumeric(id) != true) {
                        System.out.print("Invalid ID!");
                        System.out.println();
                        System.out.print("Re-Enter ID: ");
                        id = input.next();
                }

        }
}









Related Tutorials/Questions & Answers:
execption handling
execption handling  I have the following form(as example). Name:_____ Id number:____ I want to handle that as if one enter numbers in place of name,my program says please enter only character place of the name. How I should do
exception handling
exception handling  explain about exception handling
Advertisements
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
event handling
event handling  diff btwn event handling in ASP.net and in HTML
exception handling
exception handling  could you please tell me detail the concept of exception handling
File Handling
File Handling  how we do file handling of parsed XML code bu DOM in java
exception handling
exception handling   Give the exception hierarchy of Java.   Please visit the following links: http://www.roseindia.net/java/java-exception/exception-java.shtml http://www.roseindia.net/java/exceptions/exception
Null pointer execption
Null pointer execption
exception handling
exception handling  What is an exception and what are the advantages of exception handling mechanism.   Java Exception Exception... the working code and the error-handling code can be disintegrated. It also gives us
error handling mechanism
error handling mechanism  What is Java error handling mechanism
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
Exception Handling in Struts.
Exception Handling in Struts.  How you can do Exception Handling in Struts
Event handling on an image
Event handling on an image  I want to divide an image into frames and want to do event handling on the frames
exception handling in php - PHP
exception handling in php  i need few examples on exception handling in php
exception handling mechanism
exception handling mechanism  Explain Java's exception handling mechanism in detail.   Please visit the following links: http.../exceptions/catching-and-handling-exceptions.shtml
jquery session handling
jquery session handling  What is session handling in JQuery
Java exception handling
Java exception handling  what are the constraints imposed by overriding on exception handling
unicode handling in java
unicode handling in java  reading a unicode text file in java
Java event handling
Java event handling  Which java.util classes and interfaces support event handling
php error handling function
php error handling function  Is there any library or function that can be used to handle errors in PHP
File handling in Java
File handling in Java  Hi, Can any one tell me the basics of File handling in Java? ThanksADS_TO_REPLACE_1   Hi, File handling... provide very good file handling features in their api.ADS_TO_REPLACE_2 You can read
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT  Write a program to read and write the details of an employee like year of joining, Department code, salary using some byte stream classes
Try and catch in Exception Handling.
Try and catch in Exception Handling.  How can we use try and catch block in exception handling?   Here is an example of Exception handling.... Then to perform exception handling, we have used try and catch block where we have
Handling multiple buttons in HTML Form
Handling multiple buttons in HTML Form  How to handle Handling multiple buttons in HTML Form
Exception Handling in java
Exception Handling in java  what is advantage to catch smaller exception first and then normal exception. I mean we normally catch SQLException first and then Exception.   Hi, The exceptions should be from
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT  Prompt the user to enter the name of a text file to search for. If the name does not end in a .txt extension, display an error message. Search for this file in the current directory. If the file does
array in exception handling
array in exception handling  write java program to declare and initialize an array with the number given, 4,6,3,0,5,5,12 then the program will ask user to enter indexs number to display its value .using exception handling
javascript event handling examples
javascript event handling examples  javascript event handling examples   var handleClick = function(e) { // Older IEs set the `event` globally. e = window.event || e; // Older IEs use `srcElement` instead
Form Handling in Spring Framework
Form Handling in Spring Framework  I have created spring project.I created the form. When I entered the values to the form, the values should... empty. Can you send me some code for handling form in spring framework.  
Example of handling form in JSP
Example of handling form in JSP  Hi, I am learning to handle the form in JSP. Can you tell me the the example of handling form in JSP. How to handle a form in JSP? Thanks   Hi, In JSP page you can get the values
Multi-Date Handling Problem
Multi-Date Handling Problem  In our project we are using Oracle 10g as our data base, the problem is that we are picking In-date & Out-date from a calendar and on the basis of that date we are checking that on that date some
File Handling in Java
File Handling in Java  Hi, While opening a file in Java developers... was trying to find some tutorials about handling file in Java on net. I have also seen... are the use of these classes? Is there example code for explaining the File Handling
ModuleNotFoundError: No module named 'handling_databases_2'
ModuleNotFoundError: No module named 'handling_databases_2'  Hi...: No module named 'handling_databases_2' How to remove the ModuleNotFoundError: No module named 'handling_databases_2' error? Thanks   Hi
Exception Handling
Exception Handling You all are aware of Exceptions and the methods to handle... Exception Handling. Through the given code, you will come to know the use of exception handling. For this, we have allowed the user  to enter a series
Best Practice in Criteria handling? - Hibernate
Best Practice in Criteria handling?  Please explain best Practices in Hibernate Criteria handling?  Hi friend, i am sending hibernate link, you will get more information about Criteria handling , Read for more
Excpetion handling for this situation
Excpetion handling for this situation  if i have search program and if the search for a particular string fails the method should return an exception or error message. Basically user defined exception, how do i do that?  
Exception Handling - Java Beginners
handling module i.e. the message which we want to be printed. For instance, throw
event handling in jsp
event handling in jsp  i am developing a web application. i am getting a problem in event handing in jsp. in this web application there is a file generic.jsp for this jsp page i am using a database name as "priyadarshaniDB

Ads