so I'm teaching myself jQuery recently and I just came to the chapter of AJAX. There is an example showing how to check the validation for phone number and I don't know what's going on and how it works. Here is the snippet of code:   // Validate a phone number field $( "#form" ).submit(function( event ) {     var inputtedPhoneNumber = $( "#phone" ).val();      // Match only numbers     var phoneNumberRegex = /^\d*$/;      // If the phone number doesn't match the regex     if ( !phoneNumberRegex.test( inputtedPhoneNumber ) ) {          // Usually show some kind of error message here          // Prevent the form from submitting         event.preventDefault();     } else {          // Run $.ajax() here     } });   What I don't understand is this:   var phoneNumberRegex = /^\d*$/;   I did some research for phone number validation and it all has something like this: a pair of "/ /" and some stuff between them and I've never seen this before, anyone can explain what is going on here and why it works? Any help will be appreciated, thank you!
262
I don't really understand regular expressions.  Can you explain them to me in an easy-to-follow manner?  If there are any online tools or books, could you also link to them?
65332
Is it possible to catch an error when using JSONP with jQuery? I've tried both the $.getJSON and $.ajax methods but neither will catch the 404 error I'm testing. Here is what I've tried (keep in mind that these all work successfully, but I want to handle the case when it fails):  jQuery.ajax({     type: "GET",     url: handlerURL,     dataType: "jsonp",     success: function(results){         alert("Success!");     },     error: function(XMLHttpRequest, textStatus, errorThrown){         alert("Error");     } });   And also:  jQuery.getJSON(handlerURL + "&amp;callback=?",      function(jsonResult){         alert("Success!");     });   I've also tried adding the $.ajaxError but that didn't work either:  jQuery(document).ajaxError(function(event, request, settings){    alert("Error"); });   Thanks in advance for any replies!
115970
Using a ajax request I want to change content of my div.  &lt;div id="d1"&gt;202&lt;/div&gt;   So I want to change the content to a different number.  $('d1').InnerText???   Also, say I wanted to increment the number, how could I do that? Do I have to convert to int?
2660
I need to find a reg ex that only allows alphanumeric. So far, everyone I try only works if the string is alphanumeric, meaning contains both a letter and a number. I just want one what would allow either and not require both.
11336
How do you create a simple, custom rule using the jQuery Validate plugin (using ) that doesn't use a regex?  For example, what function would create a rule that validates only if at least one of a group of checkboxes is checked?
92276
I have a form that is dynamically generated, and has dynamically generated id's (and potentially classes). The forms are the same but they have the related id tacked on to the end.  How can I select each set of inputs and apply code to each one?  I was experimenting with $('input[id^=@id_airline_for_]') but could not get it to fly. I suspect I am missing some fundamental jQuery knowledge that is holding me back since I am sure this is a common problem with dynamic forms.   &lt;form method='POST'&gt;     &lt;label for="id_airline_for_8"&gt;Airline&lt;/label&gt;:     &lt;input id="id_airline_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="airline_for_8"/&gt;     &lt;label for="id_flight_number_for_8"&gt;Flight Number&lt;/label&gt;:     &lt;input id="id_flight_number_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="flight_number_for_8"/&gt;      &lt;label for="id_airline_for_17"&gt;Airline&lt;/label&gt;:     &lt;input id="id_airline_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="airline_for_17"/&gt;     &lt;label for="id_flight_number_for_17"&gt;Flight Number&lt;/label&gt;:     &lt;input id="id_flight_number_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="flight_number_for_17"/&gt;      -- snip --  &lt;/form&gt;   EDIT: I should update that i want to be able to perform some action when the input is clicked but only for classes with a matching id at the end.  To make it easy, lets say I want all inputs with a matching id at the end of the #id to disappear when one is clicked (just for arguments sake).
57647
What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.
55833
I have some client-side validation against a text box, which only allows numbers up to two decimal places with no other input.  This script was a basis for entering numeric values only, however it needs to be adapted so it can take a decimal point followed by only up to two decimal places.  I've tried things such as /[^\d].\d{0,2}, but then the replacement call wouldn't work, and I've got no idea how to do it.  Code  &lt;script type="text/JavaScript"&gt;   function valid(f) {     if (!/^\d*$/.test(f.value)) {       f.value = f.value.replace(/[^\d]/g,"");       alert("Invalid number");     }   } &lt;/script&gt;     Note  I need to match an empty string. If an empty string is provided and the form is submitted, the value defaults back to zero.
5844
I have an input type="image". This acts like the cell notes in Microsoft Excel. If someone enters a number into the text box that this input-image is paired with, I setup an event handler for the input-image. Then when the user clicks the image, they get a little popup to add some notes to the data.  My problem is that when a user enters a zero into the text box, I need to disable the input-image's event handler. I have tried the following, but to no avail.  $('#myimage').click(function { return false; });
46205
I am looking for a good example implementation of a JavaScript/HTML AutoSuggest input box to get me started. What I am trying to implement will behave "Exactly" like the Tags input box here on stackoverflow.   If it helps I am using jQuery to perform Ajax request.   I am finding examples to help me implement this however I am concerned what about best practices in the area and would love to get opinions also.
121190
I'm trying to use ajax to update two different parts of a drupal form from just one form input blur.  I have the standard ajax stuff on my input:  $my_form['my_input']['#ajax'] = array(   'callback' =&gt; 'my_callback',   'wrapper' =&gt; 'my_target_div',   'event' =&gt; 'blur', );   This is working well, swapping out my div when the input is updated ... however I also want to update another form input elsewhere in the form with different code as a result of the blur on my original input.  Is this possible, any ideas?  Edit: For clarity, here's my real world example:   Content type 'movie' Added field 'primary_title' When 'primary_title' is updated my ajax callback checks for similar strings and returns html. The html from the callback is inserted into an empty div.  That part is working great!   I'm trying to also modify the standard node 'title' input, giving it the value of 'primary_title' after I have done some regex to tidy up the string (removing "The" or "A" from the start etc) The result will be two title fields, one with the complete title 'primary_title' and one trimmed 'title' that will be useful for sorting and displaying records.
2568
I saw a potential answer here but that was for YYYY-MM-DD:   I modified the code code above for MM-DD-YYYY like so but I still can't get it to work:  String.prototype.isValidDate = function()  {      var IsoDateRe = new RegExp("^([0-9]{2})-([0-9]{2})-([0-9]{4})$");      var matches = IsoDateRe.exec(this);      if (!matches) return false;      var composedDate = new Date(matches[3], (matches[1] - 1), matches[2]);      return ((composedDate.getMonth() == (matches[1] - 1)) &amp;&amp;       (composedDate.getDate() == matches[2]) &amp;&amp;       (composedDate.getFullYear() == matches[3])); }   How can I get the above code to work for MM-DD-YYYY and better yet MM/DD/YYYY?  Thanks.
65851
Is there a well-supported, common behavior that I can expect if I do something like this in HTML:  &lt;form method="get" action="/somePage.html?param1=foo&amp;param2=foo"&gt;   &lt;input name="param2"&gt;&lt;/input&gt;   &lt;input name="param3"&gt;&lt;/input&gt; &lt;/form&gt;   Seems like this sort of thing is inherently ridiculous, but I've seen it used here and there and I was wondering what on Earth the expected behavior should be.  Are browsers smart enough to tack on "&amp;param2=whatever&amp;param3=whatever" to the action, or do they just throw in a second question mark?  Or what?  Are there cases where this is actually the right way to do things?
54866
I want to grab the value of a hidden input field in HTML.  &lt;input type="hidden" name="fooId" value="12-3456789-1111111111" /&gt;   I want to write a regular expression in Python that will return the value of fooId, given that I know the line in the HTML follows the format  &lt;input type="hidden" name="fooId" value="**[id is here]**" /&gt;   Can someone provide an example in Python to parse the HTML for the value?
82950
I'm in the process of moving an application from PHP to Java and there is heavy use of regular expressions in the code.  I've run across something in PHP that doesn't seem to have a java equivalent:  preg_replace_callback()   For every match in the regex, it calls a function that is passed the match text as a parameter.  As an example usage:  $articleText = preg_replace_callback("/\[thumb(\d+)\]/",'thumbReplace', $articleText); # ... function thumbReplace($matches) {    global $photos;    return "&lt;img src=\"thumbs/" . $photos[$matches[1]] . "\"&gt;"; }   What would be the ideal way to do this in Java?
61905
Is there some way I can show custom exception messages as an alert in my jQuery AJAX error message?  For example, if I want to throw an exception on the server side via  by throw new ApplicationException("User name already exists");, I want to catch this message ('user name already exists') in the jQuery AJAX error message.  jQuery("#save").click(function () {   if (jQuery('#form').jVal()) {     jQuery.ajax({       type: "POST",       url: "saveuser.do",       dataType: "html",       data: "userId=" + encodeURIComponent(trim(document.forms[0].userId.value)),       success: function (response) {         jQuery("#usergrid").trigger("reloadGrid");         clear();         alert("Details saved successfully!!!");       },       error: function (xhr, ajaxOptions, thrownError) {         alert(xhr.status);         alert(thrownError);       }     });   } });   On the second alert, where I alert the thrown error, I am getting undefined and the status code is 500.  I am not sure where I am going wrong. What can I do to fix this problem?
40753
Recently I have started playing with jQuery, and have been following a couple of tutorials. Now I feel slightly competent with using it (it's pretty easy), and I thought it would be cool if I were able to make a 'console' on my webpage (as in, you press the ` key like you do in  games, etc.), and then have it Ajax itself back to the server in-order to do stuff.  I originally thought the best way would be to just get the text inside the textarea, and then split it, or should I use the keyup event, convert the keycode returned to an ASCII character, append the character to a string and send the string to the server (then empty the string).  I couldn't find any information on getting text from a textarea, all I got was keyup information. Also, how can I convert the keycode returned to an ASCII character?