JavaScript - Would Like Regex Help Please
Hi,
I'm using this site Translator Editor - LingoJam I'm trying to use the regex portion of the site (click regex on the page that link goes to) to create a substitution cipher - a translates to o, etc. so far I have Code: /a/g -> o /o/g -> u Theoretically, that'd mean when I typed in "a", it would translate to "o", and when I typed in "o", it would translate to "u". Trouble is, it doesn't know when to stop. I type in "a" and it immediately returns "u", because it substitutes the "o" that it should end up as for the "u". Any help on this matter would be appreciated. Thank you. Reply With Quote 12-29-2014, 08:34 AM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts That is bound to occur if you use onkeyup to translate the letter immediately it is typed. You should create the cyphered text once the whole message is complete. All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit. Similar TutorialsI have this code so far; PHP Code: validatePhone : function(field, caption) { phoneNumber = /^[0-9]{11}$/; if(phoneNumber.test(field.val())) { return true; } return i18n('phone', caption); }, It works fine for entering an 11 digit number. However, I want to check that the number starts with either 077, 075, 079 or 078. Also, if the field is empty then it can also be accepted. How would I do this? Thanks I am creating a userscript and trying to take the following: Arian Foster (Hou - RB) and end up just with the team name: Hou You can't remove by index (which I would be able to do), because it might be K instead of RB or NO instead of Hou. I am assuming that you use Regex and the replace function to do so, but I am struggling with understanding all Regex symbols. Can someone help me with this and explain it briefly? I would appreciate it. Should alert '' twice , instead alerts original text Code: text = 'p18=100'; text = text.replace("(^|&)p100=18.*?(&|$)","") alert(text); text = text.replace(/(^|&)p100=18.*?(&|$)/g,"") alert(text); tested regex on online tester and it should be OK. ? hi, Getting on quite well, I feel. just would like you to confirm that this regex will strip out characters that cannot be in a phone number those are (imv) 0-9 - ( ) + Code: val = val.replace (/[^0-9\\s\\-\\(\\)\\+]/gi,""); // strip the characters that cannot appear in a phone number I use double backslashes to keep the perl interpreter happy. otherwise (in case it simplifies it for you), it would be Code: val = val.replace (/[^0-9\s\-\(\)\+]/gi,""); // strip the characters that cannot appear in a phone number bazz Hi: I think this is where I need to ask this. I am doing a PHP/mod_rewrite and I need to tweak one of the RegEx's used in it but I don't know the syntax. I have this bit of code: Code: <a href="http://www.mywebsite.com/Promotional.Products-Promotional.Items/Promotional-Products/<?php echo $product_id ?>-<?php echo str_replace(" ", "-", $myTitle) ?>-<?php echo $full_state ?>-Promotional-Products.html" title="<?php echo $myTitle?> <?php echo "$full_state"; ?>"><?php echo $myTitle?></a> RewriteRule ^Promotional.Products-Promotional.Items/Promotional-Products/([0-9]+)-([a-zA-Z]+)-([a-zA-Z]+)-Promotional-Products.html$ Promotional.Products-Promotional.Items/Promotional-Products.php?product_id=$1&myTitle=$2&full_state=$3 I wanted to know how I can revise the middle RegEx: Code: ...-([a-zA-Z]+)-... to include replacing all spaces with hyphens. Can someone help me with this, please. Thanks! I am trying to grab all text between <START> and <END> and have the following bits of code, but neither are returning anything. I use JS so rarely that I can't see where the problems are - Code: var ermtext = response.match(/<START>(.*?)<END>/i); if (ermtext) { result.ermtext = ermtext.replace("$1"); } Code: var patt=/<START>(.*?)<END>/i; result.ermtext = response.match(patt, "$1"); Hi All, i have this Regex which is below and im trying to validate a field when a button is clicked i may have this mest up but what the regex does it checks for 1 decimal place and returns true or false i put some comments in with the code Code: function IsNewBid() { var NewBid = document.getElementById('MainContent_txtNewBid').value; var result; result = ^[0-9]{1,10}[.]{1}[0-9]{1,2}$|^[0-9]{1,10}$(NewBid .Value) if (result 'Equals False So theres and error') Do something else{ carry on } } Any help will be highly appreciated.. Thank you for your time. Hi - I am trying to use this code to validate, function test() { var pattern = (/^\d{3}[-]?\d{2}[-]?\d{4}$/g); var pattern1 = (/^d{3}$/g); if(!pattern.test(document.myform.textInput.value)||(!pattern1.test(document.myForm.textInput.value)) ) { alert("Error!"); } } using regular expressions to compare a string from an input with two patterns that could both be valid. Therefore I'm pretty sure I need to use "||" between them both. I can't quite figure out how to get javascript to check for both patterns, only the first seems to be checked as valid. Is it something to do with the way I have my brackets? Can someone point me in right direction, Thanks The following code works as required - Code: if (result.marc.f695.subfields['a'] != "Electronic journals" && result.marc.f695.subfields['a'] != "electronic journals") { return; } However, this isn't the most efficient way to code it, especially as I want to add further possibilities, most beginning with "[Ee]lectronic. I know I need to use regexes, and think the code I need to use is something like /[Ee]lectronic/, but I use JavaScript so rarely that I'm not sure how to build this into the above expression. Can anybody help? I am attempting to remove all HTML tags with nothing in the middle. For example, I want to remove this Code: <b><i><u> </u></i></b> I've written an expression that does that, but there's an issue with it. Here's my regex: Code: messageVal = messageVal.replace(/(<[^\/>]*>)+[\s]*(<\/[^>]*>)+/g,''); The issue is that I only want to delete as many end tags as I found open tags. An example that my regex doesn't work on is... Code: <b> hello <u><i> </i></u></b> The current regex will output: Code: <b> hello I need it to return: Code: <b> hello </b> Any ideas? Hello, I have this piece of code I read from a book to remove text nodes that only have white space. Code: if (node.nodeType == 3 && ! /\S/.test(node.nodeValue)){ // code to remove the text node } Why should we use this: Code: ! /\S/.test(node.nodeValue) Instead of this? Code: /\s/.test(node.nodeValue) THIS IS NOT HOMEWORK Hi all, I'm trying to extract a URL from a string that may or may not have extra characters before and/or after the URL. I'm having a heck of a time making the regex work... when it works for one case it fails for another and I'm just not seeing why. OK, here is the code: Code: var str = 'leading junk http://h71036.www7.hp.com/hho/images/Outdoor_scene.jpg trailing junk'; var txt = str.replace(/^\s?((https?|ssh|ftp|mailto|file|www):\/\/.*?)\s?$/gi,'href:\n1 is $1\n2 is $2\n3 is $3'); alert(txt); (eventually the replacement string will be <a href="$1">$1</a> of course) What I want is of course to extract "http://h71036.www7.hp.com/hho/images/Outdoor_scene.jpg" out of the string whether of not there is leading and/or trailing "junk" around the string. Any ideas? I'm stumped... Thanks! -- Roger I am trying to run a simple replace over some css a user puts into a textarea. I would like to remove all the comments Code: /* MY COMMENT */ I have tried the following to try and escape the forward slashes but to no avail. Code: replace(/\/*(.*)\//g,""); any ideas? Thanks! i'm trying to make a validation page and i am having issues with some of them AGE - i'm not sure where to go from here Code: var age = /^[0-9 ]{3,20}$/; // trying to check age (only 18-25 is valid) Name - how do i make it so that no spaces are allowed? Code: /^[A-Za-z ]{3,50}$/ street - i have no clue where to even begin on this. i think that RegEx can't be used to validate all addresses, but something simple like 123 main street. maybe something like this Code: preg_match('/.{2,60}$/',$address) here's an example of my zip code one to give you an idea of what im going for Code: function checkZip(){ var re5digit=/^\d{5}$/ //regular expression defining a 5 digit number if (document.myform.zip.value.search(re5digit)==-1) //if match failed alert("Please enter a valid 5 digit number inside form") } HTML FORM Code: <form name="myform" onsubmit="return checkZip()"> <fieldset> <legend>Test Form</legend> Firstname*: <input type="text" name="firstname"/><br/> Lastname*: <input type="text" name="lastname"/><br/> Street*: <input type="text" name="street"/><br/> City*: <input type="text" name="city"/><br/> State*: <input type="text" name="state"/><br/> Zip*: <input type="text" name="zip"/><br/> Age*: <input type="text" name="age"/><br/> Gender*: <input type="text" name="gender"/><br/> Major/Program Choice*: <input type="text" name="major"/><br/><br/> <input type="reset" /> <input type="submit" /> what is a good way to combine these into all one function using getElementByID? i could make another function and put all the other functions in it, but i'm not sure where i can incorporate getElementByID when the verification is complete, i want to display all the info using getElementByID and innerHTML. should i make vars that hold all the info and put in after a span somewhere? Hey everyone, I'm working on a script, but I've been stopped by an error code from regex's match function. Firefox is giving me a "text.match is not a function". My assumption is that it may be the getSelection that is causing the error. Any clarification would be much appreciated! Code: function captureText(){ var txt = ""; if(window.getSelection){ var text = window.getSelection(); } else if(document.selection){ var text = document.selection.createRange().text; } else { return; } if(text != ""){ var reg = /^[A-Z](.*?)+(\.)$/g; var check = text.match(reg); alert(check); alert("You selected: "+text); if(window.getSelection){ window.getSelection().removeAllRanges(); } else if(document.selection){ text.blur(); document.selection.empty(); } else { return; } } } document.onmouseup = captureText; Thanks. This functions should replace uppercase chars with bold and lowercase with italic. It should return: Big Bad wolf, Small red ball - HI Unfortunately there's something wrong with it and I'm getting this: Big Bad wolf, Small red ball - HI Not sure what 's wrong. Code: function replaceIt(mystr){ var str = "Big Bad wolf, Small red ball - HI"; var tmppicstr = ""; var tregex = /[^a-zA-Z\s-,\/]/; var lccheck = /[:lower:]/; var ltcheck = /[a-z]/i; if(tregex.test(str) == true){ return str; } else { for(var x=0;x<=str.length;x++){ var tmpchar = str.substring(x, (x+1)); if(ltcheck.test(tmpchar) == true){ if(lccheck.test(tmpchar) != true){ tmppicstr = tmppicstr + "<b>" + tmpchar + "</b>"; }else{ tmppicstr = tmppicstr + "<i>" + tmpchar + "</i>"; } } if(tmpchar == " ") tmppicstr = tmppicstr + (" "); if(tmpchar == ",") tmppicstr = tmppicstr + ("<b>" + tmpchar + "</b>"); if(tmpchar == "-") tmppicstr = tmppicstr + ("<i>" + tmpchar + "</i>"); if(tmpchar == "/") tmppicstr = tmppicstr + ("<b class='sl'>" + tmpchar + "</b>""); } } return tmppicstr; } I am trying to validate textboxes on my form. I got everything but phone number. I have three different textboxes. One for area, one for first three, and last one for last 4numbers. everything just need to be digit numbers I guess. What is REGEX expression should be for those three different area?
Hello I need some help with validating the password strength of my form. I am actually looking for a regular expression that could force the users to have at least 2 of the following: 1. Upper and lower case. 2. Numbers 3. Symbols. Thanks in advance for any help Guys can u help how to make code 'letters only' without regex? And how to make simple captcha with the output like this => FP715,but still regex isnt allowed. Thank you |