0

I want to validate an email address using a state machine. I know there are other ways to do it like using regular expression, but I want to know can it be done using a state machine.

Any sample example or a good pointer in right direction will be appreciated

unknown
  • 13
  • 4
  • You mean something like... each character readed is an event and will transition to next state until a final state is reached? – Carlos Verdes Jan 29 '15 at 11:35
  • Statemachines are not for validation of values. They are for workflows. – Jens Jan 29 '15 at 11:36
  • Yes something like that.Just suppose that we cannot use regex or pattern matcher and we need to validate email pattern.Then how should we go about it. – unknown Jan 29 '15 at 11:36
  • @Jens You can implement a regex as a state machine where the input is accepted if you reach a specific terminal node. – Mark Rotteveel Jan 29 '15 at 12:16

1 Answers1

1

Finite automata (which are special kinds of state machines) accept the same kind of languages (so called regular languages) as regular expressions.

So if you have a regular expression that matches all email addresses and nothing else, you can construct a finite automaton that accepts all email addresses and rejects everything else.

See Wikipeda: Deterministic finite automaton for details.

Oswald
  • 31,254
  • 3
  • 43
  • 68