我想知道是否可以創建一個允許數字,字母和空格但沒有標點符號的正則表達式。不允許輸入標點符號
發生了什麼是我有一個在線貸款申請和街道地址字段中的一些用戶在他們的輸入中添加逗號(,)。在將應用程序導出爲CSV時,由於地址字段中包含逗號,因此CSV文件在錯誤的地方包含逗號。
我一直在玩一個正則表達式幾個小時,現在很好,但它不能完美。我偶爾會得到一個無法驗證的地址,但它沒有標點符號。否則它會是一個可接受的輸入,但是正則表達式不允許它被驗證。
所以不是我想什麼規定是允許(數字,空格,字母),我不能只是規定了什麼是不允許(標點符號)?後者比前者更有意義。
爲了提供信息,我已經包含了用於測試我的正則表達式的地址列表。我還包括我一直在努力的正則表達式。任何指導或協助將不勝感激
注:我已添加註釋,其中輸入無效。在無效輸入下面,我放置了一個現在有效的輸入的編輯副本。
地址:
3 TINDERWOOD CRESCENT
117HEIDERAND FLATS EESSENTHOUT STREET HEIDERAND 6511 -- no space after number
117 HEIDERAND FLATS EESSENTHOUT STREET HEIDERAND 6511
3289 ext5 edenpark
120411 mpande loation
1433b Moulton Avenue
1433 b Moulton Avenue
4 diesel rd
10821 Morubisi Street
Unit 44 Charis Place, Prosperity Road, Groblerspark -- punctuation
Unit 44 Charis Place Prosperity Road Groblerspark -- starts with word
44 Charis Place Prosperity Road Groblerspark
p box 3581 -- invalid street address
82 Akasia laan
987 leruleng sectionsaulspoort
1 lenton drive
1179 gugulethu street
1 lenton drive
10269verdwaal2 -- no spaces
10269 verdwaal 2
15 Prinsloo Street
1179 gugulethu street
13 Adler str, Eden Park -- has punctuation
13 Adler str Eden Park
410 wonderzicht, 538 de beerstr -- has punctuation
410 wonderzicht 538 de beerstr
1551 -- invalid street address
52 Koedoe Ave
26a high road orchards
Musina ext9 4363 -- number in wrong place - See below
4363 Musina ext9
18 Replubliek street
753 steve biko avenue unit2
221 Buitekant straat
54 Zone A
B1287 UMSOLWA ROAD
54 Zone A
6574 LETLHODI STREET UNIT 14
27 k street
9635 Zanemvula street
2667 nthatisi Street
498 CESSNA AVENUE
maromene 17 -- number in incorrect place - see below
17 maromene
F1 Ngoje cres MarainnhillM
6574 letlhodi street unit 14
21 tecomastreet
21 tecomastreet
07 Frara Drive
6440 MAYANA STREET THEMBALETHU GEORGE 6529
no.87 Vista Villas -- has word before number and has punctuation
87 Vista Villas
12 jama street z section --- !!!!!!!!!!!!!!!!!!!!!!!!
B1287 Umsolwa road
B 1287 Umsolwa road -- space after B
6574 letlhodi street
7658 Itsomo Steet Ext6
5dharrisson str -- no space fter number
5d harrisson str
322 Lenham Drive, Lenham -- has punctuation
322 Lenham Drive Lenham
schoolstreet 3 -- name before number
3 schoolstreet
50 Hercules Court
1546 sefatsa stand
61 sixwila street
20800 mamelodi east
colchester crescent
12 Iraq Street
12 moshoeshoe str
21 vansoelen street
12 moshoeshoe str
4102 Geelhout Street
ward 16, umzumbe, hibberdene -- has punctuation
ward 16 umzumbe hibberdene
839 Maokeng ext
28caledon drive
34 Leo ave
6423 Bandura Street, Willow Manor Ext. 1
8541 Snake Park
7 INSISWA WAY EXT 12 SHERWOOD PARK 7349
plot 50 kareebos
404 Windermere street
404 Windermere street
404 Windermere street
68 Flamink Street
68 Flamink Street
71 Eagle Dawn Zeiss road
block r3 room 105 n2 gateway
50 plein str
B206 Chapters
225 Buitenkant Street
9 Chestnut street Bonteheuwel
1740a Ben Naude Drive Zone 2
Droedam Farm
16 Aberfeldy Road The Hill
11th road 25 simonsig noordwyk
49 Soetdoring
Allensnek
12935
29 likhonda street
6 Matume street
Plot 88
22 Community Road
1100 kwamakhutha township, po amanzimtoti
9 balmoral heights, balmoral road
3 makubalo streets
3951 umthungwa street birch acres ext 23
12986 Walter Sisulu Street
11138 nongoma str
51 rudloff rd
10 Villa Palazzo, Belami Drive
321 Francis Baard Street
65 9 th street
35 Fiskaal street
14 olive street
9 manho street
38 victoria road
354 Ethafeni Section
16 Arkeldien Street
6.5 Boundary Road
100 Vlamboom Road
902 Mquma Street Bophelong
35 amsterdam street
55 fanplam gardens palmview
6213 Zone 12 Extion Sebokeng
stand no.043 ooslope
3 MURISON STREET
177 govan mbeki township
9 Chestnut street Bonteheuwel
4347 BLOCK B
1a roy cambell street
146 poole avenue
116 Woburn Street
545 Phase 5B Buhlepark
33 vos street
37 fifth street , rusthof
18 Marinda Crescent Marinda
16 chromite ave
13 kanti street 35263,Harare
67 Third Street
270 queen elizabeth ave
30 Victoria
9 manho str
26 Liebenhof Flats Young Str
1 Carter Street
10 Villa Palazzo, Belami Drive
11 vlasblomsingel progress
block 44, 513 sunset avenue
1073 mphafa road
1344 Pickerel place
1073 mphafa road
sweatpealaan 2751
44 Brummerstreet
151 Ext 3
433 10 kodi street
617 rondomstraat Louterwater
10 GREEN STREET
149 tamsanqa street
3 Newfeld Street
76 Dorp Street
5 Mabille Street
28 heathbury place
2356 joyce ndinisa road
A13 Lekoane street
正則表達式:
/^(\w*)(\d+)(\w)?\s(\w+(\s?\w+?))+$/
你的意思是像這樣的,從中可以添加一個空格,刪除下劃線? http://stackoverflow.com/questions/336210/regular-expression-for-alphanumeric-and-underscores或任何數量的其他例子,你可以搜索「字母數字正則表達式」 – Marc
以前問:http://stackoverflow.com/questions/4328500/how-can-i-strip-all-by-a-string-in-javascript-using-regex –
如果你採用MarcosPérezGude建議的路線,你可以讓用戶輸入幾乎任何東西......可能會感興趣。 – LGSon