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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:46:39+00:00 2026-06-01T02:46:39+00:00

I need to validate my textbox using JavaScript, so far i made this :

  • 0

I need to validate my textbox using JavaScript, so far i made this :

$(document).ready(function(){
$('#search_form').validate({
rules: {
 searchText:{
     required: true,    
     number: true
            },
  },
 messages: {

     searchText: {
      required: "required",
      number: "must be a number"
     }}
      })}
    );

it works fine but i also need to show a message if user presses the search button without enter any value, and of course the textbox is containing the message “please enter your number” (using placeholder).

the serach form :

<form method="get" id="search_form">
<input type="button" value="search" id="search" />
<input type="text"  name="searchText" id="searchText" placeholder="please enter your number"    />
</form> 

the current code doesn’t show anything if user presses search button without inserting a number, but if he inserts letters for example he will get the message “must be number” and if he deletes any value was there in textbox, he will get the message “required”.

i tried :

searchText:{
     required: {  depends: function()
        { return $( "#searchText" ).val() == 'please enter your number '} },    
     number: true
        },

but nothing changes.

i hope i could explain my question good.


Thanks!

you are right it works fine if i delete whatever value in the textbox i get required msg.
but since i made the validation on the form, it didn’t response on the button clocking.
how i can add a validation on the button too ?

  • 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-01T02:46:41+00:00Added an answer on June 1, 2026 at 2:46 am

    Remember that your string comparison is an exact search. It looks like you have an extra space in the code you tried, after the word “number.” Try removing that space and testing again. If the value of the textfield exactly matches the placeholder value, then your depends method should return true. Alternatively, you could try $.trim() to ensure that whitespace from the beginning and end of the string is removed.

    Another approach you may consider would be to instantiate a “original value” property (using jQuery’s data methods) so that if your placeholder value were to change, you wouldn’t need to update your JavaScript validation code.

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

Sidebar

Related Questions

hi i am using Eclipse Rcp and i need to validate the textbox that
I need to validate on exceptions when doing binding. Is this possible using Caliburn.Micro?
I need to validate a number entered by a user in a textbox using
I am using DropdownBox and TextBox in my c# application. I need to validate
I need to validate this simple pick list: <select name=<%= key %>> <option value=ETC
I need to validate a phone number in javascript. The requirements are: they should
i'm developing a WPF (.NET 3.5) application where i need to validate a textbox
I have custom control with asp textbox inside. And i need to Validate by
I need to validate a textBox entry which contains time. Time should be in
I have a text field which I need to validate using a regex. My

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.