Share on Google+Share on Google+

Dame Leta
execption handling
1 Answer(s)      5 years and a month ago
Posted in : Java Beginners

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.

Ads

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
Advertisements
exception handling
exception handling  explain about 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
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
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
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
error handling mechanism
error handling mechanism  What is Java error handling mechanism
exception handling in php - PHP
exception handling in php  i need few examples on exception handling in php
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 Struts.
Exception Handling in Struts.  How you can do Exception Handling in Struts
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
unicode handling in java
unicode handling in java  reading a unicode text file in java
Java exception handling
Java exception handling  what are the constraints imposed by overriding on exception handling
php error handling function
php error handling function  Is there any library or function that can be used to handle errors in PHP
Java event handling
Java event handling  Which java.util classes and interfaces support event handling
File handling in Java
File handling in Java  Hi, Can any one tell me the basics of File handling in Java? Thanks   Hi, File handling is very important... handling features in their api. You can read more at File Handling in Java
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads