| | |
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
you cant directly as they are two seperate languages. you could output content to the page using a script block somthign like the following
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
string g = "ZOMGGGG"; bool s = g.contains("GGGG"); Response.Write("<script type=\"text/javascript\">alert('" + s + "');</script>");
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
•
•
I mean in a form that i make in Html, i need to check that the user name name value doesn't contain the first name of the person.
so what You wrote instead of the 3rd line(replacing by) I can write return s; ? It's in a function...
so the ".contains" works on javascript?
awesome!
thanks
javascript Syntax (Toggle Plain Text)
function stringContains(string, value) { // To make this case insensitive comment out the following 2 lines // string = string.toLowerCase(); // value = value.toLowerCase(); return string.indexOf(value); } // Then call it with the following var g = 'ZOMGGGG'; var s = stringContains(g, 'GGGG');
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
Join Date: Apr 2009
Posts: 44
Reputation:
Solved Threads: 0
Bumping cause I couldn't get it to work, The function should return -1 if it doesn't contain the string right?
this is what I've done:
what's wrong?
cant i send the first_n as a value??
this is what I've done:
JavaScript Syntax (Toggle Plain Text)
function string_contains(string,value) { string=string.toLowerCase(); value=value.toLowerCase(); return string.indexOf(value); } if (string_contains(theform.pass.value,theform.first_n.value)!=-1) { theform.pass.focus(); theform.pass.select(); newalert(iderror16); return (false); }
cant i send the first_n as a value??
Last edited by peter_budo; May 9th, 2009 at 12:55 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Hi JooClops,
With this version you can choose whether the test is case-sensitive or case-insensitive and it also returns a proper boolean (not -1 | index):
I can't see why
Airshow
With this version you can choose whether the test is case-sensitive or case-insensitive and it also returns a proper boolean (not -1 | index):
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript" type="text/javascript"> //old English expression: "It's like trying to find a needle in a haystack" function string_contains(haystack, needle, caseInsensitive){ if(needle.toString() === '') { return false; } if(!caseInsensitive) { return haystack.toString().indexOf(needle.toString()) >= 0; } else { return haystack.toString().toLowerCase().indexOf(needle.toString().toLowerCase()) >= 0; } } alert( string_contains('ABCDEF', 'N') );//false alert( string_contains('ABCDEF', 'B') );//true alert( string_contains('ABCDEF', 'b') );//false alert( string_contains('ABCDEF', 'b', true) );//true alert( string_contains('ABCDEF', '') );//false </script>
caseInsensitive defaults to false (ie case-sensitive) if omitted.if(needle.toString() === '') { return false; } ensures that an empty string does not test positive (which would otherwise be the case).toString() guards against errors if non -strings are passed in.I can't see why
theform.first_n.value should not work as along as theform.first_n exists (and is within scope).Airshow
Last edited by Airshow; May 7th, 2009 at 10:39 pm.
Something strange here. I successfully edited my post above then it reverted to unedited version without a refresh or anything BUT the edited version appeared again on qoting it! That's not good behaviour. I will report is as a bug.
This is my edited version. If it is identical to the post above, then please don't blame me - it's the site software.
With this version you can choose whether the test is case-sensitive or case-insensitive and it also returns a proper boolean (not -1 | index):
I can't see why
Airshow
This is my edited version. If it is identical to the post above, then please don't blame me - it's the site software.
With this version you can choose whether the test is case-sensitive or case-insensitive and it also returns a proper boolean (not -1 | index):
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript" type="text/javascript"> //old English expression: "It's like trying to find a needle in a haystack" function string_contains(haystack, needle, caseInsensitive){ if(needle.toString() === '') { return false; } if(!caseInsensitive) { return haystack.toString().indexOf(needle.toString()) >= 0; } else { return haystack.toString().toLowerCase().indexOf(needle.toString().toLowerCase()) >= 0; } } alert( string_contains('ABCDEF', 'N') );//false alert( string_contains('ABCDEF', 'B') );//true alert( string_contains('ABCDEF', 'b') );//false alert( string_contains('ABCDEF', 'b', true) );//true alert( string_contains('ABCDEF', '') );//false </script>
caseInsensitive defaults to false (ie case-sensitive) if omitted.if(needle.toString() === '') { return false; } ensures that an empty string does not test positive (which would otherwise be the case).toString() guards against errors if non -strings are passed in.I can't see why
theform.first_n.value should not work as along as theform.first_n exists (and is within scope).Airshow
Last edited by Airshow; May 7th, 2009 at 11:00 pm.
![]() |
Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Counting
- Next Thread: Javascript Validation
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate automatically beta box bug calendar captcha cart checkbox child class column cookies createrange() css cursor decimal design dom download dropdown editor element engine enter error events explorer file focus form forms frameworks google gwt html htmlform ie8 iframe image() images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jump listbox math matrixcaptcha menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent pdf php player post problem progressbar prototype rated rating regex runtime scale scroll search select session shopping size sql star starrating stars text textarea validation w3c web website window windowofwords windowsxp wysiwyg xml \n







