javascript - Regex number filtering from textarea -


i have been looking way how filter data within textarea using regex function quite while without success. below regex want use filter uk telephone numbers.

(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))? 

fiddle: https://jsfiddle.net/qdypo04y/

i want achieve result when button clicked remove lines not meet regex? alternatively remove values not uk telephone numbers.

any guidance appreciated.

apart use of textarea element issue is:

an example is:

document.queryselector('button').addeventlistener('click', function(e) {      var txtarea = document.queryselector('textarea[rows="4"][cols="50"]');      var re = /(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?/;      var txtarr = txtarea.textcontent.split('\n');      txtarr.foreach(function(ele, idx) {          txtarr[idx] = ele + '  test result is: ' + re.test(ele);      });      txtarea.textcontent = txtarr.join('\n');  });
<textarea rows="4" cols="50">  +447222555555  0800 042 0213  2017/07/14  2017/07/17  2017/07/27  </textarea>  <button>click me</button>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -