-2

I am building a voice based email system using php and javascript. But the problem is when I give a input by spelling a email id, white spaces take places ! Unfortunately email id don't support white space. So would you please help me out ??

Here's my script:

function startDictation() {

    if (window.hasOwnProperty('webkitSpeechRecognition')) {

      var recognition = new webkitSpeechRecognition();

      recognition.continuous = false;
      recognition.interimResults = false;

      recognition.lang = "en-US";
      recognition.start();

      recognition.onresult = function(e) {
        document.getElementById('transcript').value
                                 = e.results[0][0].transcript;
        recognition.stop();
        document.getElementById('labnol').submit();
      };

      recognition.onerror = function(e) {
        recognition.stop();
      }

    }
  }

And here is my html form:

<form id="labnol" method="POST" action="">
   <div class="speech">
     <input type="text" name="ok" id="transcript" placeholder="Speak"  />
     <img  src="//i.imgur.com/cHidSVu.gif" />
   </div>
</form>
GunarathneMDD
  • 180
  • 1
  • 2
  • 11
Tahasin
  • 338
  • 1
  • 11
  • So strip off whitespaces from input – Justinas Sep 28 '18 at 10:48
  • 1
    Javascript and PHP both have string functions which can remove whitespace. What did you research? – ADyson Sep 28 '18 at 11:03
  • 1
    Possible duplicate of [Replace all whitespace characters](https://stackoverflow.com/questions/6507056/replace-all-whitespace-characters) – Mark Baijens Sep 28 '18 at 11:32
  • I am researching on a project " Email for Blind People". – Tahasin Sep 28 '18 at 11:44
  • 1
    no I meant what did you research in terms of removing whitespace from strings? i.e. the specific programming problem you're having, not your overall project. There's very little need for us to re-invent the wheel in this case. You should be able to find lots of existing samples online. – ADyson Sep 28 '18 at 12:33
  • oh..but 'research' is a big word ! I just found a amount of javascripts that didn't work. But i have got my answer and solution below. And unfortunately I don't understand ..why people here always try to unvote a question without understanding our limitation and without giving a simple answer !! Because we try first then we ask. And their extra smartness effects on our rights in this useful site. Shame ! – Tahasin Sep 28 '18 at 21:01

1 Answers1

2

Before setting the value in your input box, take away all your whitespaces. You can do that by using simple regex e.results[0][0].transcript.replace(/ /g, '');

Mukesh Verma
  • 524
  • 5
  • 9
  • Thank you so much Sir ! Thanks a lot. That solved my issue. Thank you again and sorry for my limitation to upvote your answer. – Tahasin Sep 28 '18 at 11:50