I'm experiencing a weird Javascript regex problem on Firefox 3.6 and Chrome 6 Dev. I am working on a huge form entry website which has some basic javascript validation using jQuery.
$ (document) .ready (function () {$ ("tr [id =" + "(ORJURID + '' '' '' ''). Each (function () {obj .wirerowEvents (this);}}}} obj = {"WireRowEvents": function (line) {$ ("Input [id $ = 'Orgn' (" Input "[id $ = 'Prog']"). Blur (Function () {obj.ValidateProg (this));}).), "Valid Organ": function (orgnId) {// Velitpag is similar to this var orgn = $ (orgnId); // function, besides a If (orgn.length = = 0) length of 4 instead of 5.5. Return; var orgnValue = orgn.val (); if (orgnValue.length! = 5) {if (orgnValue.length & gt; 0) { Orgn.addClass ("invalid");} and {orgn.removeClass ("invalid");}} and {if (/ (dd)} this problem The area is orgn.removeClass ("invalid"); // '/ \ d {4} / g' for the above line program} Else {orgn.addClass ("invalid");}}}} Using the above javascript (only Ready and WirelessEvent function, but the ValidateOrgn method is completely intact. That you can see only one requirements for Orgn, this is 5 digits long, and the program is 4 numbers long. The above code should work as well as Internet Explorer 7 and 8 as well as Safari 4.0.4 should work as well.
In Firefox and Chrome, the Organ and Progg on the page load are flagged as invalid, but only on the right side. There are two Orgns in full line and two programmable inputs (id with different, but ends in Organ and Prog). Looks to the left, but the right side is "invalid".
The best part is that you can click in the text box and click back and sometimes (not 100%) it will be properly valid.
When ValidateOrgn and ValidateProg in the Forbank line if (/\d {0} / g.test (OrgnValue)) returns the function, which causes it to add CSS class true , then clicking and clicking will cause it to flip forward and backward between legitimate and invalid states.
It works as expected in Internet Explorer and Safari and I can not reproduce the problem there.
Update
This was really a global flag issue. Thanks to the policy statement, I have managed to simplify the function call (it was mixed together and was flagged to clear it). The new method is now:
"valid argument": function (orgnId) {var orgn = $ (orgnId); If (orgn.length == 0) return; // I do not want to mark it as invalid if it is empty (orgn.val (. Length> gt; 0) {if (/ ^ \ d {5} $ / test (orgn.val ( )) {Orgn.removeClass ("invalid"); } Else {orgn.addClass ("invalid"); }} And {orgn.removeClass ("invalid"); Perhaps try to put your regex into a different variable, like:
< Code> // ... var re = / ^ \ d {5} $ / / // Using Plisy's comment, which I think is best advised (rename (orgnValue)) / This problem is area orgn.removeClass ("invalid"); // the above line '/ \ d {4} / for the program' else {orgn.addClass ("invalid"); } // ...
Comments
Post a Comment