Jump to content

Recommended Posts

That looks like JavaScript, is it?

 

If it is, try:

<script>
function searchfieldvalidate(value) {
   if(value.match(/^[a-z]+\s,\s[a-z]+\s,\s[a-z]+$/i)) //i turns case insensitivity on, allowing upper and lower case values of what ever is inside the match
      {
          return 'Valid';
      }
   else{
          return 'Invalid';
      }
}
</script>

 

What you had would fail on many places. The first being the multiple use of caret and dollar, which out of a character class, [], mean match at the beginning and end of the string. There can't be three beginnings and ends. Secondly, \W (the opposite of \w) means match any character that isn't a word character, meaning it would allow characters like {'#}@&*() through.

 

The third fail was you use of character classes, [a-z][A-Z]\W\,]+. Note in particular, ]+, at the end. That end close square bracket has no opening counterpart bracket so what are we repeating? The square bracket? I don't even know how that would be interpreted to be honest with you, but I can definitely tell you it's wrong.

 

I could go on but I'd rather suggest you read this:

http://www.regular-expressions.info/tutorial.html

 

Start at the introduction and end after free spacing. You will go in a matter of days from a complete novice in regular expressions to someone who can handle himself with them quite confidently. It is a very good tutorial.

 

Hope that helps you,

Joe

Link to comment
https://forums.phpfreaks.com/topic/256830-validation-help/#findComment-1316668
Share on other sites

That looks like JavaScript, is it?

 

If it is, try:

<script>
function searchfieldvalidate(value) {
   if(value.match(/^[a-z]+\s,\s[a-z]+\s,\s[a-z]+$/i)) //i turns case insensitivity on, allowing upper and lower case values of what ever is inside the match
      {
          return 'Valid';
      }
   else{
          return 'Invalid';
      }
}
</script>

 

What you had would fail on many places. The first being the multiple use of caret and dollar, which out of a character class, [], mean match at the beginning and end of the string. There can't be three beginnings and ends. Secondly, \W (the opposite of \w) means match any character that isn't a word character, meaning it would allow characters like {'#}@&*() through.

 

The third fail was you use of character classes, [a-z][A-Z]\W\,]+. Note in particular, ]+, at the end. That end close square bracket has no opening counterpart bracket so what are we repeating? The square bracket? I don't even know how that would be interpreted to be honest with you, but I can definitely tell you it's wrong.

 

I could go on but I'd rather suggest you read this:

http://www.regular-expressions.info/tutorial.html

 

Start at the introduction and end after free spacing. You will go in a matter of days from a complete novice in regular expressions to someone who can handle himself with them quite confidently. It is a very good tutorial.

 

Hope that helps you,

Joe

That looks like JavaScript, is it?

 

If it is, try:

<script>
function searchfieldvalidate(value) {
   if(value.match(/^[a-z]+\s,\s[a-z]+\s,\s[a-z]+$/i)) //i turns case insensitivity on, allowing upper and lower case values of what ever is inside the match
      {
          return 'Valid';
      }
   else{
          return 'Invalid';
      }
}
</script>

 

What you had would fail on many places. The first being the multiple use of caret and dollar, which out of a character class, [], mean match at the beginning and end of the string. There can't be three beginnings and ends. Secondly, \W (the opposite of \w) means match any character that isn't a word character, meaning it would allow characters like {'#}@&*() through.

 

The third fail was you use of character classes, [a-z][A-Z]\W\,]+. Note in particular, ]+, at the end. That end close square bracket has no opening counterpart bracket so what are we repeating? The square bracket? I don't even know how that would be interpreted to be honest with you, but I can definitely tell you it's wrong.

 

I could go on but I'd rather suggest you read this:

http://www.regular-expressions.info/tutorial.html

 

Start at the introduction and end after free spacing. You will go in a matter of days from a complete novice in regular expressions to someone who can handle himself with them quite confidently. It is a very good tutorial.

 

Hope that helps you,

Joe

 

for reason this accepts all now

Link to comment
https://forums.phpfreaks.com/topic/256830-validation-help/#findComment-1316733
Share on other sites

That looks like JavaScript, is it?

 

If it is, try:

<script>
function searchfieldvalidate(value) {
   if(value.match(/^[a-z]+\s,\s[a-z]+\s,\s[a-z]+$/i)) //i turns case insensitivity on, allowing upper and lower case values of what ever is inside the match
      {
          return 'Valid';
      }
   else{
          return 'Invalid';
      }
}
</script>

 

What you had would fail on many places. The first being the multiple use of caret and dollar, which out of a character class, [], mean match at the beginning and end of the string. There can't be three beginnings and ends. Secondly, \W (the opposite of \w) means match any character that isn't a word character, meaning it would allow characters like {'#}@&*() through.

 

The third fail was you use of character classes, [a-z][A-Z]\W\,]+. Note in particular, ]+, at the end. That end close square bracket has no opening counterpart bracket so what are we repeating? The square bracket? I don't even know how that would be interpreted to be honest with you, but I can definitely tell you it's wrong.

 

I could go on but I'd rather suggest you read this:

http://www.regular-expressions.info/tutorial.html

 

Start at the introduction and end after free spacing. You will go in a matter of days from a complete novice in regular expressions to someone who can handle himself with them quite confidently. It is a very good tutorial.

 

Hope that helps you,

Joe

That looks like JavaScript, is it?

 

If it is, try:

<script>
function searchfieldvalidate(value) {
   if(value.match(/^[a-z]+\s,\s[a-z]+\s,\s[a-z]+$/i)) //i turns case insensitivity on, allowing upper and lower case values of what ever is inside the match
      {
          return 'Valid';
      }
   else{
          return 'Invalid';
      }
}
</script>

 

What you had would fail on many places. The first being the multiple use of caret and dollar, which out of a character class, [], mean match at the beginning and end of the string. There can't be three beginnings and ends. Secondly, \W (the opposite of \w) means match any character that isn't a word character, meaning it would allow characters like {'#}@&*() through.

 

The third fail was you use of character classes, [a-z][A-Z]\W\,]+. Note in particular, ]+, at the end. That end close square bracket has no opening counterpart bracket so what are we repeating? The square bracket? I don't even know how that would be interpreted to be honest with you, but I can definitely tell you it's wrong.

 

I could go on but I'd rather suggest you read this:

http://www.regular-expressions.info/tutorial.html

 

Start at the introduction and end after free spacing. You will go in a matter of days from a complete novice in regular expressions to someone who can handle himself with them quite confidently. It is a very good tutorial.

 

Hope that helps you,

Joe

 

for reason this accepts all now

 

what?

 

anyway, here is something i put together, since i am not a fan of using regex's that have to backtrack if it can be avoided (and im bored).

 

<script type="text/javascript">

function validateStr(arr)
{
    for(index=0;index<arr.length;index++)
    {
        if(/^[a-z]+$/i.test(arr[index]) === false)
        {
            return false;
        }
    }
}

var str="test , test , test";
var arr = str.split(" , ");

if(validateStr(arr) === false)
{
    alert("failed");
}
else
{
    alert("pass");
}

</script>

 

this splits the string by the delimiter space comma space, which will isolate each case, then checks against the regex, returning false if it fails.

Link to comment
https://forums.phpfreaks.com/topic/256830-validation-help/#findComment-1316819
Share on other sites

thanks

i treid to implement it but nada

<script>
function validateStr(arr)
{
    for(index=0;index<arr.length;index++)
    {
        if(/^[a-z]+$/i.searchform(arr[index]) === false)
        {
		 alert("choose from list")
            return false;
        }
    }
}

var str = document.searchform.searchField.value
var arr = str.split(" , ");
</script>

 

im trying to get the chosen result of an auto-complete to be validated

Link to comment
https://forums.phpfreaks.com/topic/256830-validation-help/#findComment-1316840
Share on other sites

AyKay47, neat solution. However, I would like to pick you up on one point that you mentioned:

 

anyway, here is something i put together, since i am not a fan of using regex's that have to backtrack if it can be avoided (and im bored).

 

My solution has no backtracking in it...

 

 

for reason this accepts all now

 

Sorry, what?

 

thanks

i treid to implement it but nada

<script>
function validateStr(arr)
{
    for(index=0;index<arr.length;index++)
    {
        if(/^[a-z]+$/i.searchform(arr[index]) === false)
        {
		 alert("choose from list")
            return false;
        }
    }
}

var str = document.searchform.searchField.value
var arr = str.split(" , ");
</script>

 

im trying to get the chosen result of an auto-complete to be validated

 

And again, what?

 

Can you please give a bit more information with your posts. What error's are being returned? Have you checked that you are passing the right information to the function? Which alert is popping up from AyKay's response? Your asking people to blind code a solution to a problem that you can't put into words. It's quite difficult.

Link to comment
https://forums.phpfreaks.com/topic/256830-validation-help/#findComment-1316854
Share on other sites

AyKay47, neat solution. However, I would like to pick you up on one point that you mentioned:

 

anyway, here is something i put together, since i am not a fan of using regex's that have to backtrack if it can be avoided (and im bored).

 

My solution has no backtracking in it...

 

 

ummm.... yeah I just looked it over again and it shouldn't backtrack on a match you're right.

 

thanks

i treid to implement it but nada

<script>
function validateStr(arr)
{
    for(index=0;index<arr.length;index++)
    {
        if(/^[a-z]+$/i.searchform(arr[index]) === false)
        {
		 alert("choose from list")
            return false;
        }
    }
}

var str = document.searchform.searchField.value
var arr = str.split(" , ");
</script>

 

im trying to get the chosen result of an auto-complete to be validated

 

wait... you edited the function and didn't call it in your code at all..  :facewall:

since you clearly do not understand how it should be implemented, i will hold you hand:

 

<script>
function validateStr(arr) //don't touch this function
{
    for(index=0;index<arr.length;index++)
    {
        if(/^[a-z]+$/i.test(arr[index]) === false)
        {
            return false;
        }
    }
}

var str = document.searchform.searchField.value; //validate that this is in the correct format to be split
var arr = str.split(" , "); //delimiter can be changed if desired
if(validateStr(arr) === false)
    alert("failed");
else
    alert("passed");
</script>

Link to comment
https://forums.phpfreaks.com/topic/256830-validation-help/#findComment-1316913
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.