Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:27:15+00:00 2026-06-15T12:27:15+00:00

The function I wrote check if the input is a letter or not. If

  • 0

The function I wrote check if the input is a letter or not. If not it shows an alert message then erases the content. It works fine when I just enter a letter, but if I enter numbers, it shows the message to enter letters which is ok, but when I enter letters in the box, it still pops up the message and ask me to enter a letter. Why? How can I fix it?

<%//javascript file %>
<script type="text/javascript" >
function allLetter(value)  
{  
 var letters = /^[A-Za-z]+$/;  
 if(value.match(letters))  
   {
    return true;  
   }  
 else  
   {  
   alert("first, last and middle name contain only letters");  
   return false;  
   }  
} 

function checkform ( form )
{
  // see http://www.thesitewizard.com/archive/validation.shtml
  // for an explanation of this script and how to use it on your
  // own website

  // ** START **
  if ((form.firstName.value == "") || (form.lastName.value == "") ) {
    alert("Please enter both your first and last name.");
    form.firstName.focus();
    form.lastName.focus();
    return false ;
  }
  // ** END **
  return true ;
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Names and country of residence page</title>
</head>
<body>
<%

Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

    // Registering Postgresql JDBC driver with the DriverManager
    Class.forName("org.postgresql.Driver");

    // Open a connection to the database using DriverManager
    conn = DriverManager.getConnection(
        "jdbc:postgresql://localhost:5432/assignment1",
        "postgres","Km81920265");


        // Create the statement
        Statement statement = conn.createStatement();

        // Use the created statement to SELECT
        // the student attributes FROM the Student table.
        rs = statement.executeQuery("SELECT * FROM countries_and_states WHERE is_country='t'");


%>

<%//first delcare input %>
Please enter your first name, last name and middle initial:<p>
<form method="get" action="address.jsp" onsubmit="return checkform(this);">
<%//store input into session %>
Your first name :<input type="text" size="15" name="firstName" onchange="if(!allLetter(this.value)){this.value= ' ';} "/><p/>
Your last name  :<input type="text" size="15" name="lastName" onchange="if(!allLetter(this.value)){this.value= ' ';} "/><p/>
Your middle name:<input type="text" size="15" name="middleName" onchange="if(!allLetter(this.value)){this.value= ' ';} "/><p/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:27:16+00:00Added an answer on June 15, 2026 at 12:27 pm

    Change letters to match /^\s*[A-Za-z]+\s*$/ or trim the whitespace around the value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a function I wrote quite some time ago that works fine, but
I wrote a function to check whether a word is palindrome or not but
I wrote a javascript function to validate that the user input data is not
Question: How would one write a function to check and return whether or not
Here is a function I wrote to break a long string into lines not
I am trying to write a function that can check whether or not some
I wrote a function in PHP to check username and password from MySQL database
I tried to write a function to check key code with JavaScript. It's working
I wrote function onclick of a element <div class=left_collapsed>Որոնում</div> <div class=container style=display: none;> <ul>
How would I use DLLImport pinvoke to invoke a function i wrote in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.