在离子中使用正则表达式

时间:2016-09-23 18:36:41

标签: angularjs ionic-framework

我正在使用Ionic来显示用户的联系人列表。因此,当用户输入数字并单击添加按钮时,它应该在列表中显示为(011)123-1234,并且每个条目都应该遵循这一点。我试图在标签中设置模式,但无法显示电话号码。请帮帮我。

<input type="tel" maxlength="10"  ng-model="phone" pattern="/(?:\(?\+\d{2}\)?\s*)?\d+(?:[ -]*\d+)*$/"> <br>
     <button ng-click="home()">Home</button></n>
     <button ng-click="add()" value="Add">Add</button><br>

1 个答案:

答案 0 :(得分:0)

您应该使用remote: [18:47:20] Using gulpfile /var/www/wikaike-devel/gulpfile.js remote: [18:47:20] Starting 'babel'... remote: argv path: server/server.js remote: argv branch: devel remote: abort: 0��� ������$0������ remote: remote: ==== Stack trace ============================================ remote: remote: Security context: 0x3733462d <JS Object>#0# remote: 1: /* anonymous */ [/var/www/wikaike-devel/node_modules/is-utf8/is-utf8.js:~2] (this=0x373346d5 <JS Global Object>#1#,bytes=0x57528e71 <a Buffer>#2#) remote: 2: /* anonymous */(aka /* anonymous */) [/var/www/wikaike-devel/node_modules/vinyl-fs/node_modules/strip-bom/index.js:9] (this=0x37308091 <undefined>,arg=0x57528e71 <a Buffer>#2#) remote: 3: /* anonymous */(aka /* anonymous */) [/var/www/wikaike-devel/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js:11] (this=0x37308091 <undefined>,err=0x37308081 <null>,data=0x57528e71 <a Buffer>#2#) remote: 4: /* anonymous */ [fs.js:266] (this=0x373346d5 <JS Global Object>#1#,er=0x37308081 <null>) remote: 5: /* anonymous */ [/var/www/wikaike-devel/node_modules/vinyl-fs/node_modules/graceful-fs/graceful-fs.js:102] (this=0x373346d5 <JS Global Object>#1#,er=0x37308081 <null>) remote: 7: oncomplete [fs.js:107] (this=0x575292e9 <an Object>#3#) remote: 8: arguments adaptor frame: 1->0 remote: remote: ==== Details ================================================ remote: remote: [1]: /* anonymous */ [/var/www/wikaike-devel/node_modules/is-utf8/is-utf8.js:~2] (this=0x373346d5 <JS Global Object>#1#,bytes=0x57528e71 <a Buffer>#2#) { remote: // stack-allocated locals remote: var i = 11629 remote: // expression stack (top to bottom) remote: [02] : 0 remote: [01] : 2019638 remote: --------- s o u r c e c o d e --------- remote: function (bytes)?{? var i = 0;? while(i < bytes.length)? {? if( (// ASCII? bytes[i] == 0x09 ||? bytes[i] == 0x0A ||? bytes[i] == 0x0D ||? (0x20 <= bytes[i] && bytes[i] <= 0x7E)? )? ) {? ... remote: remote: ----------------------------------------- remote: } remote: remote: [2]: /* anonymous */(aka /* anonymous */) [/var/www/wikaike-devel/node_modules/vinyl-fs/node_modules/strip-bom/index.js:9] (this=0x37308091 <undefined>,arg=0x57528e71 <a Buffer>#2#) { remote: // expression stack (top to bottom) remote: [02] : 0x57528e71 <a Buffer>#2# remote: [01] : 0x373346d5 <JS Global Object>#1# remote: [00] : 0x44fecad1 <JS Function>#4# remote: --------- s o u r c e c o d e --------- remote: function (arg) {??if (typeof arg === 'string') {???return arg.replace(/^\ufeff/g, '');??}???if (Buffer.isBuffer(arg) && isUtf8(arg) &&???arg[0] === 0xef && arg[1] === 0xbb && arg[2] === 0xbf) {???return arg.slice(3);??}???return arg;?} remote: ----------------------------------------- remote: } remote: remote: [3]: /* anonymous */(aka /* anonymous */) [/var/www/wikaike-devel/node_modules/vinyl-fs/lib/src/getContents/bufferFile.js:11] (this=0x37308091 <undefined>,err=0x37308081 <null>,data=0x57528e71 <a Buffer>#2#) { remote: // expression stack (top to bottom) remote: [03] : 0x57528e71 <a Buffer>#2# remote: [02] : 0x37308091 <undefined> remote: [01] : 0x44fecaf5 <JS Function>#5# remote: [00] : 0x57524f79 <a File>#6# remote: --------- s o u r c e c o d e --------- remote: function (err, data) {? if (err) {? return cb(err);? }? file.contents = stripBom(data);? cb(null, file);? } remote: ----------------------------------------- remote: } remote: remote: [4]: /* anonymous */ [fs.js:266] (this=0x373346d5 <JS Global Object>#1#,er=0x37308081 <null>) { remote: // expression stack (top to bottom) remote: [03] : 0x57528e71 <a Buffer>#2# remote: [02] : 0x37308081 <null> remote: [01] : 0x37308091 <undefined> remote: [00] : 0x57527ca9 <JS Function>#7# remote: --------- s o u r c e c o d e --------- remote: function (er) {? if (size === 0) {? // collected the data into the buffers list.? buffer = Buffer.concat(buffers, pos);? } else if (pos < size) {? buffer = buffer.slice(0, pos);? }?? if (encoding) buffer = buffer.toString(encoding);? return callback(er, buffer);?... remote: remote: ----------------------------------------- remote: } remote: remote: [5]: /* anonymous */ [/var/www/wikaike-devel/node_modules/vinyl-fs/node_modules/graceful-fs/graceful-fs.js:102] (this=0x373346d5 <JS Global Object>#1#,er=0x37308081 <null>) { remote: // expression stack (top to bottom) remote: [02] : 0x37308081 <null> remote: [01] : 0x373346d5 <JS Global Object>#1# remote: [00] : 0x57529081 <JS Function>#8# remote: --------- s o u r c e c o d e --------- remote: function (er) {? onclose()? cb(er)? } remote: ---------------/var/opt/gitlab/git-data/repositories/root/wikaike.git/hooks/deploy-hook: line 42: 26701 Bus error /usr/bin/gulp babel --branch $branch --path $i 代替ng-pattern

结帐ngPattern documentation了解详情。

pattern

另外,我相信你正在寻找一个不是正则表达式的掩码指令。

我建议this one运行良好且易于使用。