Check if a string contains a specific number in JavaScript

Possible Duplicate: JavaScript: string contains I want to check if a string contains a specific number in JavaScript, how can I rewrite the statement s contain d in below code? var s = '11/14/2012'; var d = '14'; if (s contain d) { //... } My case is similar to Check if a string contains a certain number, but how can I implement this action in JavaScript? Thanks 更简单的方法是使用ind

检查一个字符串是否包含JavaScript中的特定数字

可能重复: JavaScript:字符串包含 我想检查一个字符串是否包含JavaScript中的特定数字,我如何在下面的代码中重写s contain d的语句? var s = '11/14/2012'; var d = '14'; if (s contain d) { //... } 我的情况类似于检查一个字符串是否包含特定的数字,但我该如何在JavaScript中实现此操作? 谢谢 更简单的方法是使用index Of。 if(s.indexOf(d) > -1) var s = '11/14/2012'; var d = '14'; if (s.match(d))

How to check if filename contains substring in JavaScript?

This question already has an answer here: How to check whether a string contains a substring in JavaScript? 49 answers if you have the file names you can use something like: if(theFileName.indexOf('myfilethree') > -1) { do your magic here because "myfilethree" is present in the name! } However, I am not aware of any way to read a directory index in javascript. There are two parts

如何检查文件名是否包含JavaScript中的子字符串?

这个问题在这里已经有了答案: 如何检查一个字符串是否包含JavaScript中的子字符串? 49个答案 如果你有文件名,你可以使用类似于: if(theFileName.indexOf('myfilethree') > -1) { do your magic here because "myfilethree" is present in the name! } 但是,我不知道有什么方法可以在javascript中读取目录索引。 有两部分内容:获取目录中的文件列表,然后搜索它们的子字符串。 我将从情节部分开始,因为这

How to verify "Contains" using JavaScript

Possible Duplicate: JavaScript: string contains In the below code I have to check whether the textbox contains @ and . . I tried writing the below code which is not working. Anybody please do provide me with the correct syntax. function emailval(objval) { if (obj.value.contains("@") && obj.value.contains(".")) { document.getElementById(mid).style.background

如何使用JavaScript验证“包含”

可能重复: JavaScript:字符串包含 在下面的代码中,我必须检查文本框是否包含@和. 。 我试着写下面的代码,这是行不通的。 任何人都请给我提供正确的语法。 function emailval(objval) { if (obj.value.contains("@") && obj.value.contains(".")) { document.getElementById(mid).style.backgroundColor = "#BDD470"; } else { document.getElementById(

javascript if statement if url contains substring

You can use the indexOf method // Function is used to determine whether a string contains another string function contains(search, find) { ///<summary>Sees if a string contains another string</summary> ///<param type="string" name="search">The string to search in</param> ///<param type="string" name="find">The string to find</param> ///<retu

javascript if语句如果url包含子字符串

您可以使用indexOf方法 // Function is used to determine whether a string contains another string function contains(search, find) { ///<summary>Sees if a string contains another string</summary> ///<param type="string" name="search">The string to search in</param> ///<param type="string" name="find">The string to find</param> ///<returns type=

Check a string that MUST contain another string

This question already has an answer here: How to check whether a string contains a substring in JavaScript? 49 answers Read the documentation: MDC String.indexOf :) indexOf returns the index the match was found. This may be 0 (which means "found at the beginning of string") and 0 is a falsy value. indexOf will return -1 if the needle was not found (and -1 is a truthy value).

检查一个必须包含另一个字符串的字符串

这个问题在这里已经有了答案: 如何检查一个字符串是否包含JavaScript中的子字符串? 49个答案 阅读文档:MDC String.indexOf :) indexOf返回找到匹配的索引。 这可能是0(意思是“在字符串的开头找到”),0是一个虚假值。 如果未找到针, indexOf将返回-1(-1是真值)。 因此,需要调整测试逻辑以使用这些返回码工作。 找到的字符串(在开始或其他地方): index >= 0或index > -1或index != -1 ; 未找到字符

'in' operator in JavaScript. String comparison

This question already has an answer here: How to check whether a string contains a substring in JavaScript? 49 answers I think one way is to use String.indexOf() 'aaa' .indexOf('a') > -1 In javascript the in operator is used to check whether an object has a property 你正在寻找indexOf 。 'aaa'.indexOf('a') == 0 //if a char exists in the string, indexOf will return

'in'运算符在JavaScript中。 字符串比较

这个问题在这里已经有了答案: 如何检查一个字符串是否包含JavaScript中的子字符串? 49个答案 我认为一种方法是使用String.indexOf() 'aaa' .indexOf('a') > -1 在javascript中,in运算符用于检查对象是否具有属性 你正在寻找indexOf 。 'aaa'.indexOf('a') == 0 //if a char exists in the string, indexOf will return // the index of the first instance of the char 'aaa'.indexOf('b

if sentence contains string

This question already has an answer here: How to check whether a string contains a substring in JavaScript? 49 answers The method you're looking for is indexOf (Documentation). Try the following if (sentence.indexOf('Hello World') >= 0) { alert('Yes'); } else { alert('No'); } 试试这个: if (sentence.indexOf("Hello World") != -1) { alert("Yes"); } else { alert("No"); }

如果句子包含字符串

这个问题在这里已经有了答案: 如何检查一个字符串是否包含JavaScript中的子字符串? 49个答案 你正在寻找的方法是indexOf (Documentation)。 尝试以下操作 if (sentence.indexOf('Hello World') >= 0) { alert('Yes'); } else { alert('No'); } 试试这个: if (sentence.indexOf("Hello World") != -1) { alert("Yes"); } else { alert("No"); }

what is the best way to check if a string exists in another?

Possible Duplicate: JavaScript: string contains I'm looking for an algorithm to check if a string exists in another. For example: 'Hello, my name is jonh LOL.'.contains('Hello, my name is jonh'); //true 'LOL. Hello, my name is jonh'.contains('Hello, my name is jonh'); //true Thanks in advance. Use indexOf : 'Hello, my name is jonh LOL.'.indexOf('Hello, my name is jonh') > -1; //

检查另一个字符串是否存在的最佳方法是什么?

可能重复: JavaScript:字符串包含 我正在寻找一种算法来检查另一个字符串是否存在。 例如: 'Hello, my name is jonh LOL.'.contains('Hello, my name is jonh'); //true 'LOL. Hello, my name is jonh'.contains('Hello, my name is jonh'); //true 提前致谢。 使用indexOf : 'Hello, my name is jonh LOL.'.indexOf('Hello, my name is jonh') > -1; //true 'LOL. Hello, my name is jonh'.indexOf('Hello, my

like .Contains in jquery

Possible Duplicate: JavaScript: string contains Jquery: How to see if string contains substring in asp .net c# i use string aa = "aa bb"; if (aa.Contains("aa")) { //Some task } i want to same thing in client side means in JQuery.Some thing like below. var aa = "aa bb"; if(aa. -----want help here){ } There is any method to do this.Thanks. 使用String.indexOf() MDN Do

像jQuery中包含.Contains

可能重复: JavaScript:字符串包含 Jquery:如何查看字符串是否包含子字符串 在asp.net .NET C#我使用 string aa = "aa bb"; if (aa.Contains("aa")) { //Some task } 我想在客户端意味着在jQuery中的相同的东西。像下面的一些东西。 var aa = "aa bb"; if(aa. -----want help here){ } 有任何方法可以做到这一点。谢谢。 使用String.indexOf() MDN Docs方法if( aa.indexOf('aa') != -1 ){ //

if variable contains

Possible Duplicate: JavaScript: string contains I have a postcode variable and want to use JS to add a location into a different variable when the postcode is changed/entered. So for example if ST6 is entered I would want Stoke North to be entered. I somehow need to do an if statement to run through eg if(code contains ST1) { location = stoke central; } else if(code contains ST2) {

如果变量包含

可能重复: JavaScript:字符串包含 我有一个postcode变量,并希望在更改/输入邮编时使用JS将位置添加到不同的变量中。 例如,如果输入ST6,我想要输入Stoke North。 我不知何故需要做一个if语句来通过例如 if(code contains ST1) { location = stoke central; } else if(code contains ST2) { location = stoke north; } 等等... 我将如何去做这件事? 它不检查'代码'是否等于一个值,但如果它包