我讓用戶提交電話號碼。對於如何輸入沒有限制。 我需要從這個電話號碼是兩件事;區號(不包括前導0)和其餘的數字。兩者都沒有非數字字符。從電話號碼獲取區號
可能出現的情況,用戶可能輸入:
- 0707-123456
- 0707-12 34 56
- 08-123 456 78
- 08-123 45 67
- 031-123 45 67
- 031-12 34 56
- 0480-12 34 56
- 0480-123 45
- +46(0)8 12 345 67 8
結果我想獲得(二NSString的或INT或任何): 用戶輸入:0707123456
瓦爾1:70
瓦爾2:7123456
用戶輸入:+46(0)8 12 345 67 8
瓦爾1:8
瓦爾2:12345678
這些是區域代碼:
70,730,76,271,322,174,472,371,589,961,960,570,583,226, 624,915,531,652,932,662,921,278,243,33,142,661,456,693,914,912,431,571,295,586,552,653,942,534,271, 381,471,171,246,16,413,223,346,515,23,590,122,585,157,241,943,684,258,528,645,241,493,371,158,498,可以使用本發明的方法制備化合物525,555,595,591,390,514,551,672,970,693,26,31,511,563,975,643,582,220,175,35,696,644,297,922,928,224,本發明的化合物可以通過使用本發明的化合物來製備,所述化合物爲: 621,647,36,916,923,480,505,454,294,586,455,54,150,554,320 ,980,494,435,580,977,612,44,550,640,226,19,300,227,303,221,430,925,418,584,247,474,302,478,692,510 ,581,13,642,372,651,657,240,920,46,950,523,913,157,40,280,953,496,159,501,433,530,142,553,250,141 ,392,524,563,499,587,223,930,11,176,918,512,481,155,380,622,297,454,250,304,479,491,643,155,978,435號公報,911,973,623,175,934,457,459,472,924,682,248,224,26,414,416,511,910,222,142,294,500,240,620,952,8 ,951,290,152,433,526,670,695,60,565,220,418,585,680,325,687,246,564,533,253,225,382,293,270,121,456 ,504,502,293,60,477,304,417,691,560,16,486,345,325,140,410,520,156,954,292,506,522,613,321,90,18 ,143,393,156,123,281,512,340,383,125,940,492,933,151,495,498,981,976,322,521,935,370,490,21,470,411 ,571,532,690,647,573,474,941,120,476,251,929,431,144,485,295,19,173,660,291,63,292,173,926,927,
我該如何用Objective-c做到這一點?
爲什麼在你的第二個例子VAR2 8位數?這些都是美國的電話號碼嗎? – Danny
不與'+ 46'國家代碼 - 不,他們不是美國的電話號碼 –
好吧,如果你想在世界的所有可能的區號,準備寫一個巨大的正則表達式:d – FailedDev