473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ignore cAse and hyphens

I want to read a string and check it ignoring case and hyphens.

Expand|Select|Wrap|Line Numbers
  1. if (string=='password'){
  2. return true;
  3. }
How can I make this true for PasS-WorD or P-A-Sswo-Rd or whatever?
Oct 10 '07 #1
3 1911
gits
5,390 Expert Mod 4TB
hi ...

moved from the js-articles section to the forum ... please don't post question to the articles sections ...

to your problem ... you may use something like the following:

Expand|Select|Wrap|Line Numbers
  1. var value = 'PasS-WorD';
  2.  
  3. // we test with a regEx after replacing all '-' with ''
  4. var test = /password/i.test(value.replace(/-/g, ''));
  5.  
  6. // test is now true
  7. alert(test);
it works for 'P-A-Sswo-Rd' too :) ...

kind regards
Oct 10 '07 #2
awesome, thanks gits.

not sure what "/password/i." does, but I used this

Expand|Select|Wrap|Line Numbers
  1. string='PaSs-W-or-D';
  2. string=string.toLowerCase();
  3. string=string.replace(/-/g, '');
  4.  
  5. if (string=='password'){
  6. alert('case and hyphens ignored');
  7. }
probably more clumsy, but worked.
Oct 10 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

Expand|Select|Wrap|Line Numbers
  1. /password/i
is a regular Expression that ignores case (thats th i switch), where

Expand|Select|Wrap|Line Numbers
  1. /-/g
matches globally (thats the g switch) ...

so you could use one line for your task with that what i showed you :)

kind regards
Oct 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bob Rosen | last post by:
Can anyone provide an intrinsic justification (i.e. not related to popularity or standardization) for using camel case notation? Just saying to distinguish certain variable types is not sufficient...
5
by: richard_thomas | last post by:
Hi, I'm having trouble running the following query: select * from message where text_body like ' ----------%' ie, five spaces followed by at least ten hyphens. The query doesn't...
18
by: Gustaf Liljegren | last post by:
IE does, and I can't remember this used to be a problem in Netscape. I guess someone in the Mozilla team just came up with a Smart Idea about the True Semantics of the Hyphen Minus character. :-(...
8
by: Danny | last post by:
I've read the recent post about not breaking at hyphens in HTML documents. I *want* breaking to occur at hyphens. (for 'hyphen' read 'minus sign') IE6 and Opera7.54 both break phrases such as...
2
by: Pierre | last post by:
Hello, I would like to write a regexp that can be either case sensitive or that can ignore the case based on a variable (value would be either 'i' or ''). For instance in the below code the...
46
by: James Harris | last post by:
Before I embark on a new long-term project I'd appreciate your advice on how to split up long names. I would like to keep the standards for command names the same as that for variable names....
4
by: A.M | last post by:
Hi, How can I set the option of RegularExpressionValidator to RegexOptions.IgnoreCase ? Thanks, Alan
0
by: hamby | last post by:
Hi all, I am trying to read an XML file, which has the encoding: <?xml version="1.0" encoding="ISO-8859-1"?> I then iterate through the elements until I find the element I want, then I get...
4
by: almurph | last post by:
Hi, Wondering if you can help me here. Given a string length "m" how do you insert 3 hyphens in differing positions such that the following conditions are met: a. all positions are covered...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.