I created a simple project in Dart whose intention is to validate an email field when a button is clicked, showing an error message .
However, the RegExp.hasMath function is always returning false . I do not know what could be wrong.
Below is the HTML code and then Dart.
<!-- formulario.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Teste e-mail</title>
</head>
<body>
<div class="form">
<div>
<input type="text" id="inputEmail">
</div>
</div>
<div class="error">
<span id="errorMessage"></span>
</div>
<script type="application/dart" src="validate.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
// validate.dart
import 'dart:html';
void main(){
querySelector('#submit').onClick.listen(verifyEmail);
}
void verifyEmail(Event e) {
String email = querySelector('#inputEmail').text;
querySelector('#errorMessage').text =
isValidEmail(email) ? '' : 'E-mail inválido!';
}
bool isValidEmail(String email){
RegExp reg = new RegExp(r"^[^@]+@[^@]+\.[^@]+$");
return reg.hasMatch(email);
}