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 8037953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:04:37+00:00 2026-06-05T03:04:37+00:00

Here is my Jsfiddle . Actually I am trying to validate a text field

  • 0

Here is my Jsfiddle.

Actually I am trying to validate a text field before it submits.
I want to show the errormsg_box if the text field is empty, if it’s not then submit a form,
but here it is not working
Here is my script:

$("form").submit(function(event) {

    var text_val = $('#emailid').val();
    alert(text_val);
    if (text_val != ' ') {
        $('.errormsg_box').show();
        return false;
        event.preventdefault();
    }
    else if (text_val != '') {
        $('.errormsg_box').hide();
        return true;
    }
});
  • 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-05T03:04:38+00:00Added an answer on June 5, 2026 at 3:04 am
    if ($.trim(text_val) === "") {
        return false;
        // Or
        event.preventDefault(); // event.preventdefault()
                                // javascript is case sensitive.
    }
    

    Full code:

    $("form").submit(function(event) {
        var text_val = $('#emailid').val();
    
        if ($.trim(text_val) === "") {
            $('.errormsg_box').show();
            return false;
        }
        else 
            $('.errormsg_box').hide();
    });​
    

    Live DEMO

    If you want to validte the text is a valid email address:

    var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!regex.test($.trim(text_val)))
        ... Error
    

    Live DEMO

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

Sidebar

Related Questions

Here is jsfiddle ! I am trying to make user page where he can
Please check it here: http://jsfiddle.net/9VaW2/1/ I want jData be available outside $http({method: 'POST', url:
Take a look here: http://jsfiddle.net/Nvntm/1/ The Support navigation item actually disappears on Firefox (and
I have a little javascript app set up here: http://jsfiddle.net/faYMH/ What i want it
Here is a fiddle: http://jsfiddle.net/5s7vv/ What I want to do is have 2 buttons
An example jsfiddle is here . Try to hover the red square and then
Fiddle here: http://jsfiddle.net/emJcx/1/ I have a drop down menu that is a simple show
I think an image best describes this: JS FIDDLE HERE: http://jsfiddle.net/fp2Ak/ What I want
I've made a demo of what I'm trying to do here in jsFiddle: http://jsfiddle.net/clowerweb/SbNdb/
my jsfiddle is here: http://jsfiddle.net/justmelat/QnKeZ/ I hide fieldsets on load of page, then display

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.