JavaScript - Identify Ilegal Characters In Variable
Hi to all!
I have a jquery script that checks in the database if a user exists and if true it returns a big red X next to the field, I now want to implement a statement to only alow nmbers (0-9) letters (a-z) and (_) (-) So the only help i need is to construct a if statement similar to the one below, if it is possible, and if not, any advice on howto. Code: if(any thing else but 0-9, a-z _ -){ $('#username').css('border', '3px #C33 solid'); $('#tick').hide(); $('#cross').fadeIn(); } Full script: Code: <script> $(document).ready(function(){ $('#username').keyup(username_check); }); function username_check(){ var username = $('#username').val(); if(username == \"\" || username.length < 4){ $('#username').css('border', '3px #CCC solid'); $('#tick').hide(); } else{ jQuery.ajax({ type: \"POST\", url: \"general/check.php\", data: 'username='+ username, cache: false, success: function(response){ if(username == \"admin\"){ $('#username').css('border', '3px #C33 solid'); $('#tick').hide(); $('#cross').fadeIn(); } else if(response == 1){ $('#username').css('border', '3px #C33 solid'); $('#tick').hide(); $('#cross').fadeIn(); }else{ $('#username').css('border', '3px #090 solid'); $('#cross').hide(); $('#tick').fadeIn(); } } }); } } </script> Thank you in advance. Similar TutorialsI need to declare a variable (astString) and initialise it with a string of asterisks. astString needs to be the same length as another variable (otherString). otherString changes it value regularly so I think I need to use the .length property in some way but I can't see how! This should be simple but it's eluding me completely. I'm using buttons to scroll content in an iframe. Works fine on IE and Chrome. Firefox cannot identify the frame and I get this error Error: window.frames.iframe is undefined My code is Code: var mypage= eval(window.frames["iframe"].contentlayer.style); My iframe is Code: <iframe id="iframe" src="scroll.asp" width="320" height="480" scrolling="no" marginheight="0" marginwidth="0"> And the scroll.asp is Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> </head> <body> <DIV ID="contentlayer" STYLE="position:absolute; width:320px; left: 0px; top: 0px"> <img src="images/scroll.jpg" width=320 height=960> </div> </body> </html> Any idea why Firefox can't understand the reference? Hi, I have a programing problem that have been around for ages. I have search on google using several expressions and words and after hours of digging i'm still unable to do it. I would like to get a value from a HTML page hosted remotely with an inconstant value. Then define this value and name as a javascript variable and apply or show in my page. Thanks for all the help P.S. Is there any way to make a domain lookup in javascript? I mean a user enters a domain and the script converts to an ip and shows to the user. If not thanks, probably it can only be done in the server side... Hello I have a php page in which I declared a js variable... right at the top of the page... <script type="text/javascript"> var tester = 0; </script> Later in the page I test this variable... <script type="text/javascript"> if (tester==1){ do some stuff!! } </script> But I keep getting an error variable _tester undefined Am I missing something obvious... I am new to js... but this seems really straightforward I don't know how I should do ? Quote: <html> <head> <script type="text/javascript"> function add(a,b){ y=a+b return y } var aaa = add(one,two) //one needs to get somehow get the value of yil, in this case 10 var one = function reas(){i=10;if(i<10){yil = 15}; else{yil = 10; yil = one;}; var two = 20; document.write(y) </script> </head> </html> also why doesn't this work? Quote: <html> <head> <script type="text/javascript"> function adder(a,b){ var k=a+b; return k } var hes=adder(5,kol); kol=40; alert(hes); </script> </head> </html> you cannot have variables in callback functions? Hi! I have a javascript in the head of the document which has a variable named "ref2" ... ref2 is already working as I can see its value working in another function. I need to send this variable as the value of a hidden field in the form which is in the body of the document. This is my JavaScript Code: Code: function WriteContactFormStatement1 () { var ContactFormValue = ref2; document.write('<input type="hidden" name="UReferrersName" value="' + ContactFormValue + '" />'); } var WriteContactFormStatement = WriteContactFormStatement1 (); And at the end of my form, before the submit button, I have the following code: Code: <!-- START -- Javascript to print the statement for UReferrersName --> <script language="JavaScript" type="text/JavaScript"> //WriteContactFormStatement(); document.write (WriteContactFormStatement); </script> <!-- End -- Javascript to print the statement for UReferrersName --> When I execute the form, it doesn't work the way it should, plus, gives me a word "undefined" next to the "Submit" button ..... Please help !... - Xeirus. Need to know how to define hex characters for the following; var x = hex value var y new Array(hex value, hex value, etc) document.write(hex value) I'm trying to figure out the proper way to correctly get each full-formation of encoded html (of Unicode), so that I could assign each HTML encoding with its each Unicode characters HTML Encoded Unicode: &#2344;&#2351;&#2366; &#2344;&#2375;&#2346;&#2366;&#2354; I want to retrieve each encoded HTML and assign them into array like this Code: var my_array = new Array(); my_array [0] = "2344"; my_array [1] = "2351"; my_array [2] = "2366"; my_array [3] = "2344"; my_array [4] = "2375"; my_array [5] = "2346"; my_array [6] = "2366"; my_array [7] = "2354"; Thanks in Advance for helps Hi, So I've got an array called questions_raw Code: questions raw = [ ["<Q1> Question", "choice1","choice2", "choice3"], ["<Q2> Question", "choice1","choice2", "choice3"], ... ] And I want to list all of the questions, but not the choices/answers. So far, I've managed to list just the questions, but because another function randomly sorts them, I need to sort them back into numerical order for a separate function (displaying the questions) I use characters (>,^) at the front to separate them into different answer types (just to explain the code) I try this to cut each string down so that they can be sorted numerically/alphebetically - Code: function linearlist() { var list = []; var tempStr = ""; for (var l = 0; l < 145; l++) { tempStr = questions_raw[l][0]; list[l] = tempStr; } if (list.charAt(0)== " " ) list = list.substring(3) ; if (list.charAt(0)== ">" ) list = list.substring(3) ; if (list.charAt(0)== "^" ) list = list.substring(3) ; var sorted = list.sort(); document.Qtext2form.Qtext2.value = sorted.join("\n"); } But it doesn't like it - because "it has no method charAt" Any idea what i'm missing? Is it just that you have to put the [l] in every time you call a variable? Cheers My credit card processing service will only accept English characters. I need to detect entries in the form that are using non English characters. Is there a way in Javascript to create a function to force a string to UTF-8? My idea is to do something like function forceUTF8(X){ Y = ???? X; return Y; } if ( stringA != forceUTF8(stringA) alert ("You must use English Characters"); Hi I have a CMS system using Tinymce and after making some alterations noticed the updates weren't showing up. After much messing (sql, set up etc) I started to delete the content bits at a time and came to the conclusion that is was the character ' as in what's any ideas why this is and how to solve it i'm thinking its due to php code! Cheers I have a simple function like this: Code: function chars_remaining() { var remaining = 200 - document.getElementById("text_box").value.length; document.getElementById("number").innerHTML = 'Characters Remaining: ' + remaining; } And I call this onkeyup on the textarea. 200 chars max and what happens is when they type a character, it will still stay at 200 until they press another key. So when it will be 199, it should actually be 198. Onkeyup, onkeydown, onkeypress will all do the same thing. How can I make it so that as soon as they press a key it changes right away? Also I insert this into my database with mysql_real_escape_string, which is limited at 200 chars. When they keep typing and get to 0 remaining characters if they had any quotes, backslashes, etc. they will get added and thus some of their text will be cut off. I.e. lets say the text ended with "good luck". If they had 3 quotes in their text it might end up being "good l" instead because 3 backslashes had to be used to escape. So would the best thing to do be to count a quote, backslash, etc. as two characters instead of one. How would I do that in JS? I am using the below javascript to verify a text input box but I would also like to require atleast 3 characters being entered before allowing the user to search. How do I accomplish that? Thanks in advance! Code: <script language="JavaScript"> <!-- /*********************************************** * Required field(s) validation v1.10- By NavSurf * Visit Nav Surf at http://navsurf.com * Visit http://www.dynamicdrive.com/ for full source code ***********************************************/ function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("words"); // Enter field description to appear in the dialog box var fieldDescription = Array("Company Name"); // dialog message var alertMsg = "Please complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> hi all, am doing a check on my fields, so that they only contain certain characters and numbers. i have this. var validEntry = /^[a-zA-Z0-9@$&"]+/; but this also captures a space in between words as an error. can somebody please tell me on how to avoid this. thanks. Can some one help me, I want to replace the characters from a string and I have tried with this script: Code: var v5=form.description.value.replace(/#/, "%23"); But it only changes the first character from the string. Turning #### into %23### but I want them all transformed. So, I have this javasript code in HEAD <script type="text/javascript"> <!-- function validateThis(registerForm) { if (registerForm.firstname.value == 'Name') { alert("Oops"); return false; } else { return true; } } //--> </script> with this form in BODY <form action="register.php" method="post" name="registerForm" onSubmit="return validateThis(this)"> <input type="text" value="Name" onclick="if(this.value=='Name'){this.value=''}" onblur="if(this.value==''){this.value='Name'}" name="firstname"> </form> and I want to put a text with Greek characters instead of value "Name". I tried it and the "function validateThis" didn't work. The form just passes it and returns true. I tried also hexadecimal code,HTML entities and numeric HTML entities and didn't work either. What I should I do? Thank you in advance! I have a textbox ( I am using asp.net ). I want to use that textarea as rich text box. The text in textarea is submitted to database and then displayed. So, I can use <b><u> tags, but I want to use smileys too. I need a simple code for it. My logic is simple..., Whatever text is written inside the textarea is first read and when a group of specific character like Code: " :) ;) x-(" are found, that characters should be colored to red . So, a Code: :) will appear as Code: :) . This logic is simple but I am new to javascript programming, it cant implement it. Can a provide a javascript for this, or if you have better but simple code plz let me know. Code: <script type="text/javascript" src="external.php?type=js"></script> <script language="" type="text/javascript"> <!-- for (x = 0; x < 10; x++) { document.writeln("<a href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a>, "); } //--> </script> My code will display 10 posts, however at the very end it will display an extra ", " which bugs me. How can I strip those last two characters. |