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

  • SEARCH
  • Home
  • 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 7670105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:44:46+00:00 2026-05-31T15:44:46+00:00

I’m trying to make a form validation method. and I’m facing a couple of

  • 0

I’m trying to make a form validation method. and I’m facing a couple of problems:

  1. After submitting the form and the fields are not filled correctly, all the other inputs get erased.

2.The focus() is not working at all.

Here’s the html form:

    <form name ="reg" onsubmit ="return checkValidation(this)">
    <p><label for="name">שם</label><input type="text" name="name" id="name" /> </p>
    <p><label for="e-mail">אימייל</label><input type="text" name="email" id="email" /> </p>
    <p><label for="password">סיסמא</label><input type="password" name="password" id="password" /></p>
    <p><label for="sex">זכר</label><input type="radio" value="male"id="radio" name="radio" /></p>
    <p><label for="sex">נקבה</label><input type="radio" value="female" name="radio" id="radio" /></p>
    <p><label for="checkbox">אופנוע</label><input type="checkbox" name="bike" id="bike" value="Bike" /> </p>
    <p><label for="checkbox">מכונית</label><input type="checkbox" name="car" id="car" value="Car" /> </p>
    <p><label for="favorite">שחקן המועדף עליך</label>
    <select>
    <option value="פרקינס">דורון פרקינס</option>
    <option value="סופוקליס שחורציאניטיס">סופוקליס שחורציאניטיס</option>
    <option value="עומרי כספי">עומרי כספי</option>
    <option value="דייויד בלו">דייויד בלו</option>
    </select></p>       
    <p><label for="text"></label>
    <textarea  > רשום את הודעתך פה! </textarea></p>    
    <p><label for="reset"></label><input type="reset" name="reset" /></p>
    <p class="submit"><input type="submit" value="שלח"/></p>
</form>

And here’s the javascript code:

    <script type = "text/javascript">

    function checkValidation()
    {
        isValidName();
        isValidEmail();
        isValidPass();

    }
    function isValidName()
    {
        var check = false;
        var Allowed = "qwertyuiopasdfghjklzxcvbnm";
        var str = document.reg.name.value.toLowerCase();
        if(str == "")
        {
        alert("Enter your name!");
        reg.name.focus();
        return false;
        }

        for(i = 0;i<str.length;i++)
        {

            for(k = 0;k<Allowed.length;k++)
            {
                if(str[i] == Allowed[k])
                {
                    check = true;

                }
            }
            if(check == false)
            {
            alert("Please enter a valid name");
            reg.name.focus();
            return false;
            }
            check = false;
        }
        return true;

    }
    function isValidEmail()
    {
        str = reg.email.value;
        var lastAtPos = str.lastIndexOf('@');
        var lastDotPos = str.lastIndexOf('.');
        if (lastAtPos < lastDotPos && lastAtPos > 0 && str.indexOf("..") == -1 
        && str.indexOf('@@') == -1 && lastDotPos > 2 && (str.length - lastDotPos) > 2)
        {
            return true;
        }
        else
        {
            alert("Please enter a valid email");
            reg.email.focus();
            return false;
        }
    }
    function isValidPass()
    {
        var notAllowed = "./;'[]{}\()-=_|";
        var str = reg.password.value;
        if(str.length > 6)
        {
        alert("The password must be lower than 6 characters");
        reg.password.focus();
        return false;
        }
        for(i = 0;i<str.length;i++)
        {
            for(k = 0;k<notAllowed.length;k++)
            {
                if(str[i] == notAllowed[k])
                {
                alert("You cannot use the following letters: " +notAllowed);
                reg.password.focus();
                return false;
                }
            }
        }
        return true;
    }

</script>

Thanks alot for helpers!

  • 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-05-31T15:44:47+00:00Added an answer on May 31, 2026 at 3:44 pm
    1. The function checkValidation() does not return anything:

      <form name ="reg" onsubmit ="return checkValidation(this)">

    You need to check each sub-function and return false ASAP.

    function checkValidation() {
        var go = isValidName();
        if (go){
            go = isValidEmail();
        }
        if (go){
            go = isValidPass();
        }
        return go;
    }

    2: rather than var Allowed = "qwertyuiopasdfghjklzxcvbnm";, you should be using a regular expression and eliminate the costly loop you have later on.

    3: Consider using a tested form validation framework like jQuery Validate.

    4: I second @Dan's post on needing server-side validation.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

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.