1

I want to add disallow user to submit form if the user input contains 'xyz.co.in' in the input fields but this should be done with html5 pattern, I do not want to do it with jquery or javacript. Can anyone please help me with what should be its respective pattern, I mean what should go in pattern field in <input type='text' pattern='<some pattern goes here>'/>

So that user can insert anything in the input field except xyz.co.in.

UPDATE

Here is what I have so far:

<!doctype html>
<html>
    <head>
        <title>disallow a pattern</title>
    </head>
    <body>
        <form action="" >
            <input type="text" pattern="^(?!.*\bxyz\.co\.in\b)" />
            <input type="submit" name="Go1" value="Go"/>
        </form>
    </body>
</html>

4
  • 1
    So, you shared with us what you need. Now, please let us know where you got stuck. Commented Sep 7, 2015 at 9:51
  • @stribizhev I think I dint understand what you are asking for but still let me try to explain, Actually I know home to apply patters to define the acceptable strings I mean I know how to write a pattern to define that my input field should have at least 3 words or start with so and so string but I do not know how to restrict user if he enters so and so string anywhere in the string. Does it answers your question? Commented Sep 7, 2015 at 10:22
  • Good, please add the code you have written so far to your question. Commented Sep 7, 2015 at 10:26
  • Well I havent written anything Actually I do not know what to write neither I find any site explaining how to write patterns to disallow a string in pattern. Commented Sep 7, 2015 at 10:29

1 Answer 1

3

Disallowing some string to be inside a larger string can be done with a negative look-ahead anchored at the beginning.

Here is an example that disallows xyz.co.in in an input string:

^(?!.*xyz\.co\.in).*

See demo

If you want to allow mmmxyz.co.inmmmm in the input string, add word boundaries \b around the word.

Note that pattern attribute value is anchored by default, so ^ might not be necessary, and .* is necessary to ensure the entire string is matched.

UPDATE

To disallow input of xyz.co.in and allow any other, use

^(?!xyz\.co\.in$).*
Sign up to request clarification or add additional context in comments.

5 Comments

it does not allow me to enter anything have a look at jsbin.com/zuwiqijafu/edit?html,output
Ah yes, it expects the whole string match. Add .* at the end.
But I want something like user can enter anything except xyz.co.in
P.S. could you please remove the -1 from my question
I can only give you +1, as that minus is not mine. Does my solution work for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.